###### The Activation of Anti-Asian Vote Choice ### 
#Nathan Kar Ming Chan and Vivien Leung
#Political Behavior


#load in packages
library(haven)
library(MASS)
library(stargazer)
library(ggplot2)
library(corrplot)
library(psy)
library(readxl)
library(sjPlot)
library(effects)
library(psych)
library(dplyr)
library(REdaS)
library(nnet)
library(survey)
library(ggpubr)

#import data
anes08 <- read.csv("/Users/nchan7/Documents/anes08_replication.csv")
anes12 <- read.csv("/Users/nchan7/Documents/anes12_replication.csv")
anes16 <- read.csv("/Users/nchan7/Documents/anes16_replication.csv")
anes20 <- read.csv("/Users/nchan7/Documents/anes20_replication.csv")

##CODE ANES 08

#vote choice 08 mccain
anes08$mccain.general08 <- NA
anes08$mccain.general08 <- as.numeric(anes08$mccain.general08)
anes08$mccain.general08[anes08$V085044a==1] <- 0
anes08$mccain.general08[anes08$V085044a==3] <- 1
anes08$mccain.general08[anes08$V085044a==7] <- 0
addmargins(table(anes08$mccain.general08))

#asian american feeling thermometer (reverse coding)
anes08$therm.test.asian.am08 <- NA
anes08$therm.test.asian.am08 <- as.numeric(anes08$V085064v)
table(anes08$therm.test.asian.am08)
anes08$therm.test.asian.am08[anes08$V085064v==-9|
                               anes08$V085064v==-8|
                               anes08$V085064v==-6|
                               anes08$V085064v==-2] <- NA
table(anes08$therm.test.asian.am08)
anes08$therm.test.asian.am08[anes08$V085064v==0] <- 100
anes08$therm.test.asian.am08[anes08$V085064v==1] <- 99
anes08$therm.test.asian.am08[anes08$V085064v==2] <- 98
anes08$therm.test.asian.am08[anes08$V085064v==3] <- 97
anes08$therm.test.asian.am08[anes08$V085064v==4] <- 96
anes08$therm.test.asian.am08[anes08$V085064v==5] <- 95
anes08$therm.test.asian.am08[anes08$V085064v==6] <- 94
anes08$therm.test.asian.am08[anes08$V085064v==7] <- 93
anes08$therm.test.asian.am08[anes08$V085064v==8] <- 92
anes08$therm.test.asian.am08[anes08$V085064v==9] <- 91
anes08$therm.test.asian.am08[anes08$V085064v==10] <- 90
anes08$therm.test.asian.am08[anes08$V085064v==11] <- 89
anes08$therm.test.asian.am08[anes08$V085064v==12] <- 88
anes08$therm.test.asian.am08[anes08$V085064v==13] <- 87
anes08$therm.test.asian.am08[anes08$V085064v==14] <- 86
anes08$therm.test.asian.am08[anes08$V085064v==15] <- 85
anes08$therm.test.asian.am08[anes08$V085064v==16] <- 84
anes08$therm.test.asian.am08[anes08$V085064v==17] <- 83
anes08$therm.test.asian.am08[anes08$V085064v==18] <- 82
anes08$therm.test.asian.am08[anes08$V085064v==19] <- 81
anes08$therm.test.asian.am08[anes08$V085064v==20] <- 80
anes08$therm.test.asian.am08[anes08$V085064v==21] <- 79
anes08$therm.test.asian.am08[anes08$V085064v==22] <- 78
anes08$therm.test.asian.am08[anes08$V085064v==23] <- 77
anes08$therm.test.asian.am08[anes08$V085064v==24] <- 76
anes08$therm.test.asian.am08[anes08$V085064v==25] <- 75
anes08$therm.test.asian.am08[anes08$V085064v==26] <- 74
anes08$therm.test.asian.am08[anes08$V085064v==27] <- 73
anes08$therm.test.asian.am08[anes08$V085064v==28] <- 72
anes08$therm.test.asian.am08[anes08$V085064v==29] <- 71
anes08$therm.test.asian.am08[anes08$V085064v==30] <- 70
anes08$therm.test.asian.am08[anes08$V085064v==31] <- 69
anes08$therm.test.asian.am08[anes08$V085064v==32] <- 68
anes08$therm.test.asian.am08[anes08$V085064v==33] <- 67
anes08$therm.test.asian.am08[anes08$V085064v==34] <- 66
anes08$therm.test.asian.am08[anes08$V085064v==35] <- 65
anes08$therm.test.asian.am08[anes08$V085064v==36] <- 64
anes08$therm.test.asian.am08[anes08$V085064v==37] <- 63
anes08$therm.test.asian.am08[anes08$V085064v==38] <- 62
anes08$therm.test.asian.am08[anes08$V085064v==39] <- 61
anes08$therm.test.asian.am08[anes08$V085064v==40] <- 60
anes08$therm.test.asian.am08[anes08$V085064v==41] <- 59
anes08$therm.test.asian.am08[anes08$V085064v==42] <- 58
anes08$therm.test.asian.am08[anes08$V085064v==43] <- 57
anes08$therm.test.asian.am08[anes08$V085064v==44] <- 56
anes08$therm.test.asian.am08[anes08$V085064v==45] <- 55
anes08$therm.test.asian.am08[anes08$V085064v==46] <- 54
anes08$therm.test.asian.am08[anes08$V085064v==47] <- 53
anes08$therm.test.asian.am08[anes08$V085064v==48] <- 52
anes08$therm.test.asian.am08[anes08$V085064v==49] <- 51
anes08$therm.test.asian.am08[anes08$V085064v==50] <- 50
anes08$therm.test.asian.am08[anes08$V085064v==51] <- 49
anes08$therm.test.asian.am08[anes08$V085064v==52] <- 48
anes08$therm.test.asian.am08[anes08$V085064v==53] <- 47
anes08$therm.test.asian.am08[anes08$V085064v==54] <- 46
anes08$therm.test.asian.am08[anes08$V085064v==55] <- 45
anes08$therm.test.asian.am08[anes08$V085064v==56] <- 44
anes08$therm.test.asian.am08[anes08$V085064v==57] <- 43
anes08$therm.test.asian.am08[anes08$V085064v==58] <- 42
anes08$therm.test.asian.am08[anes08$V085064v==59] <- 41
anes08$therm.test.asian.am08[anes08$V085064v==60] <- 40
anes08$therm.test.asian.am08[anes08$V085064v==61] <- 39
anes08$therm.test.asian.am08[anes08$V085064v==62] <- 38
anes08$therm.test.asian.am08[anes08$V085064v==63] <- 37
anes08$therm.test.asian.am08[anes08$V085064v==64] <- 36
anes08$therm.test.asian.am08[anes08$V085064v==65] <- 35
anes08$therm.test.asian.am08[anes08$V085064v==66] <- 34
anes08$therm.test.asian.am08[anes08$V085064v==67] <- 33
anes08$therm.test.asian.am08[anes08$V085064v==68] <- 32
anes08$therm.test.asian.am08[anes08$V085064v==69] <- 31
anes08$therm.test.asian.am08[anes08$V085064v==70] <- 30
anes08$therm.test.asian.am08[anes08$V085064v==71] <- 29
anes08$therm.test.asian.am08[anes08$V085064v==72] <- 28
anes08$therm.test.asian.am08[anes08$V085064v==73] <- 27
anes08$therm.test.asian.am08[anes08$V085064v==74] <- 26
anes08$therm.test.asian.am08[anes08$V085064v==75] <- 25
anes08$therm.test.asian.am08[anes08$V085064v==76] <- 24
anes08$therm.test.asian.am08[anes08$V085064v==77] <- 23
anes08$therm.test.asian.am08[anes08$V085064v==78] <- 22
anes08$therm.test.asian.am08[anes08$V085064v==79] <- 21
anes08$therm.test.asian.am08[anes08$V085064v==80] <- 20
anes08$therm.test.asian.am08[anes08$V085064v==81] <- 19
anes08$therm.test.asian.am08[anes08$V085064v==82] <- 18
anes08$therm.test.asian.am08[anes08$V085064v==83] <- 17
anes08$therm.test.asian.am08[anes08$V085064v==84] <- 16
anes08$therm.test.asian.am08[anes08$V085064v==85] <- 15
anes08$therm.test.asian.am08[anes08$V085064v==86] <- 14
anes08$therm.test.asian.am08[anes08$V085064v==87] <- 13
anes08$therm.test.asian.am08[anes08$V085064v==88] <- 12
anes08$therm.test.asian.am08[anes08$V085064v==89] <- 11
anes08$therm.test.asian.am08[anes08$V085064v==90] <- 10
anes08$therm.test.asian.am08[anes08$V085064v==91] <- 9
anes08$therm.test.asian.am08[anes08$V085064v==92] <- 8
anes08$therm.test.asian.am08[anes08$V085064v==93] <- 7
anes08$therm.test.asian.am08[anes08$V085064v==94] <- 6
anes08$therm.test.asian.am08[anes08$V085064v==95] <- 5
anes08$therm.test.asian.am08[anes08$V085064v==96] <- 4
anes08$therm.test.asian.am08[anes08$V085064v==97] <- 3
anes08$therm.test.asian.am08[anes08$V085064v==98] <- 2
anes08$therm.test.asian.am08[anes08$V085064v==99] <- 1
anes08$therm.test.asian.am08[anes08$V085064v==100] <- 0
addmargins(table(anes08$therm.test.asian.am08))

#asian american feeling thermomter recoded and rescaled
anes08$therm.asian.americans08 <- NA
anes08$therm.asian.americans08 <- as.numeric((anes08$therm.test.asian.am08)/100)
addmargins(table(anes08$therm.asian.americans08))

#hispanic thermometer
anes08$therm.test.hispanic08 <- NA
anes08$therm.test.hispanic08 <- as.numeric(anes08$V085064a)
table(anes08$therm.test.hispanic08)
anes08$therm.test.hispanic08[anes08$V085064a==-9|
                               anes08$V085064a==-8|
                               anes08$V085064a==-6|
                               anes08$V085064a==-2] <- NA
table(anes08$therm.test.hispanic08)
anes08$therm.test.hispanic08[anes08$V085064a==0] <- 100
anes08$therm.test.hispanic08[anes08$V085064a==1] <- 99
anes08$therm.test.hispanic08[anes08$V085064a==2] <- 98
anes08$therm.test.hispanic08[anes08$V085064a==3] <- 97
anes08$therm.test.hispanic08[anes08$V085064a==4] <- 96
anes08$therm.test.hispanic08[anes08$V085064a==5] <- 95
anes08$therm.test.hispanic08[anes08$V085064a==6] <- 94
anes08$therm.test.hispanic08[anes08$V085064a==7] <- 93
anes08$therm.test.hispanic08[anes08$V085064a==8] <- 92
anes08$therm.test.hispanic08[anes08$V085064a==9] <- 91
anes08$therm.test.hispanic08[anes08$V085064a==10] <- 90
anes08$therm.test.hispanic08[anes08$V085064a==11] <- 89
anes08$therm.test.hispanic08[anes08$V085064a==12] <- 88
anes08$therm.test.hispanic08[anes08$V085064a==13] <- 87
anes08$therm.test.hispanic08[anes08$V085064a==14] <- 86
anes08$therm.test.hispanic08[anes08$V085064a==15] <- 85
anes08$therm.test.hispanic08[anes08$V085064a==16] <- 84
anes08$therm.test.hispanic08[anes08$V085064a==17] <- 83
anes08$therm.test.hispanic08[anes08$V085064a==18] <- 82
anes08$therm.test.hispanic08[anes08$V085064a==19] <- 81
anes08$therm.test.hispanic08[anes08$V085064a==20] <- 80
anes08$therm.test.hispanic08[anes08$V085064a==21] <- 79
anes08$therm.test.hispanic08[anes08$V085064a==22] <- 78
anes08$therm.test.hispanic08[anes08$V085064a==23] <- 77
anes08$therm.test.hispanic08[anes08$V085064a==24] <- 76
anes08$therm.test.hispanic08[anes08$V085064a==25] <- 75
anes08$therm.test.hispanic08[anes08$V085064a==26] <- 74
anes08$therm.test.hispanic08[anes08$V085064a==27] <- 73
anes08$therm.test.hispanic08[anes08$V085064a==28] <- 72
anes08$therm.test.hispanic08[anes08$V085064a==29] <- 71
anes08$therm.test.hispanic08[anes08$V085064a==30] <- 70
anes08$therm.test.hispanic08[anes08$V085064a==31] <- 69
anes08$therm.test.hispanic08[anes08$V085064a==32] <- 68
anes08$therm.test.hispanic08[anes08$V085064a==33] <- 67
anes08$therm.test.hispanic08[anes08$V085064a==34] <- 66
anes08$therm.test.hispanic08[anes08$V085064a==35] <- 65
anes08$therm.test.hispanic08[anes08$V085064a==36] <- 64
anes08$therm.test.hispanic08[anes08$V085064a==37] <- 63
anes08$therm.test.hispanic08[anes08$V085064a==38] <- 62
anes08$therm.test.hispanic08[anes08$V085064a==39] <- 61
anes08$therm.test.hispanic08[anes08$V085064a==40] <- 60
anes08$therm.test.hispanic08[anes08$V085064a==41] <- 59
anes08$therm.test.hispanic08[anes08$V085064a==42] <- 58
anes08$therm.test.hispanic08[anes08$V085064a==43] <- 57
anes08$therm.test.hispanic08[anes08$V085064a==44] <- 56
anes08$therm.test.hispanic08[anes08$V085064a==45] <- 55
anes08$therm.test.hispanic08[anes08$V085064a==46] <- 54
anes08$therm.test.hispanic08[anes08$V085064a==47] <- 53
anes08$therm.test.hispanic08[anes08$V085064a==48] <- 52
anes08$therm.test.hispanic08[anes08$V085064a==49] <- 51
anes08$therm.test.hispanic08[anes08$V085064a==50] <- 50
anes08$therm.test.hispanic08[anes08$V085064a==51] <- 49
anes08$therm.test.hispanic08[anes08$V085064a==52] <- 48
anes08$therm.test.hispanic08[anes08$V085064a==53] <- 47
anes08$therm.test.hispanic08[anes08$V085064a==54] <- 46
anes08$therm.test.hispanic08[anes08$V085064a==55] <- 45
anes08$therm.test.hispanic08[anes08$V085064a==56] <- 44
anes08$therm.test.hispanic08[anes08$V085064a==57] <- 43
anes08$therm.test.hispanic08[anes08$V085064a==58] <- 42
anes08$therm.test.hispanic08[anes08$V085064a==59] <- 41
anes08$therm.test.hispanic08[anes08$V085064a==60] <- 40
anes08$therm.test.hispanic08[anes08$V085064a==61] <- 39
anes08$therm.test.hispanic08[anes08$V085064a==62] <- 38
anes08$therm.test.hispanic08[anes08$V085064a==63] <- 37
anes08$therm.test.hispanic08[anes08$V085064a==64] <- 36
anes08$therm.test.hispanic08[anes08$V085064a==65] <- 35
anes08$therm.test.hispanic08[anes08$V085064a==66] <- 34
anes08$therm.test.hispanic08[anes08$V085064a==67] <- 33
anes08$therm.test.hispanic08[anes08$V085064a==68] <- 32
anes08$therm.test.hispanic08[anes08$V085064a==69] <- 31
anes08$therm.test.hispanic08[anes08$V085064a==70] <- 30
anes08$therm.test.hispanic08[anes08$V085064a==71] <- 29
anes08$therm.test.hispanic08[anes08$V085064a==72] <- 28
anes08$therm.test.hispanic08[anes08$V085064a==73] <- 27
anes08$therm.test.hispanic08[anes08$V085064a==74] <- 26
anes08$therm.test.hispanic08[anes08$V085064a==75] <- 25
anes08$therm.test.hispanic08[anes08$V085064a==76] <- 24
anes08$therm.test.hispanic08[anes08$V085064a==77] <- 23
anes08$therm.test.hispanic08[anes08$V085064a==78] <- 22
anes08$therm.test.hispanic08[anes08$V085064a==79] <- 21
anes08$therm.test.hispanic08[anes08$V085064a==80] <- 20
anes08$therm.test.hispanic08[anes08$V085064a==81] <- 19
anes08$therm.test.hispanic08[anes08$V085064a==82] <- 18
anes08$therm.test.hispanic08[anes08$V085064a==83] <- 17
anes08$therm.test.hispanic08[anes08$V085064a==84] <- 16
anes08$therm.test.hispanic08[anes08$V085064a==85] <- 15
anes08$therm.test.hispanic08[anes08$V085064a==86] <- 14
anes08$therm.test.hispanic08[anes08$V085064a==87] <- 13
anes08$therm.test.hispanic08[anes08$V085064a==88] <- 12
anes08$therm.test.hispanic08[anes08$V085064a==89] <- 11
anes08$therm.test.hispanic08[anes08$V085064a==90] <- 10
anes08$therm.test.hispanic08[anes08$V085064a==91] <- 9
anes08$therm.test.hispanic08[anes08$V085064a==92] <- 8
anes08$therm.test.hispanic08[anes08$V085064a==93] <- 7
anes08$therm.test.hispanic08[anes08$V085064a==94] <- 6
anes08$therm.test.hispanic08[anes08$V085064a==95] <- 5
anes08$therm.test.hispanic08[anes08$V085064a==96] <- 4
anes08$therm.test.hispanic08[anes08$V085064a==97] <- 3
anes08$therm.test.hispanic08[anes08$V085064a==98] <- 2
anes08$therm.test.hispanic08[anes08$V085064a==99] <- 1
anes08$therm.test.hispanic08[anes08$V085064a==100] <- 0
addmargins(table(anes08$therm.test.hispanic08))

#reverse code the hispanic thermometer
anes08$therm.hispanics08 <- NA
anes08$therm.hispanics08 <- as.numeric((anes08$therm.test.hispanic08)/100)
addmargins(table(anes08$therm.hispanics08))

#white thermometer
anes08$therm.test.white08 <- NA
anes08$therm.test.white08 <- as.numeric(anes08$V085064c)
anes08$therm.test.white08[anes08$V085064c==-9|
                            anes08$V085064c==-8|
                            anes08$V085064c==-6|
                            anes08$V085064c==-2] <- NA
table(anes08$therm.test.white08)
anes08$therm.test.white08[anes08$V085064c==0] <- 100
anes08$therm.test.white08[anes08$V085064c==1] <- 99
anes08$therm.test.white08[anes08$V085064c==2] <- 98
anes08$therm.test.white08[anes08$V085064c==3] <- 97
anes08$therm.test.white08[anes08$V085064c==4] <- 96
anes08$therm.test.white08[anes08$V085064c==5] <- 95
anes08$therm.test.white08[anes08$V085064c==6] <- 94
anes08$therm.test.white08[anes08$V085064c==7] <- 93
anes08$therm.test.white08[anes08$V085064c==8] <- 92
anes08$therm.test.white08[anes08$V085064c==9] <- 91
anes08$therm.test.white08[anes08$V085064c==10] <- 90
anes08$therm.test.white08[anes08$V085064c==11] <- 89
anes08$therm.test.white08[anes08$V085064c==12] <- 88
anes08$therm.test.white08[anes08$V085064c==13] <- 87
anes08$therm.test.white08[anes08$V085064c==14] <- 86
anes08$therm.test.white08[anes08$V085064c==15] <- 85
anes08$therm.test.white08[anes08$V085064c==16] <- 84
anes08$therm.test.white08[anes08$V085064c==17] <- 83
anes08$therm.test.white08[anes08$V085064c==18] <- 82
anes08$therm.test.white08[anes08$V085064c==19] <- 81
anes08$therm.test.white08[anes08$V085064c==20] <- 80
anes08$therm.test.white08[anes08$V085064c==21] <- 79
anes08$therm.test.white08[anes08$V085064c==22] <- 78
anes08$therm.test.white08[anes08$V085064c==23] <- 77
anes08$therm.test.white08[anes08$V085064c==24] <- 76
anes08$therm.test.white08[anes08$V085064c==25] <- 75
anes08$therm.test.white08[anes08$V085064c==26] <- 74
anes08$therm.test.white08[anes08$V085064c==27] <- 73
anes08$therm.test.white08[anes08$V085064c==28] <- 72
anes08$therm.test.white08[anes08$V085064c==29] <- 71
anes08$therm.test.white08[anes08$V085064c==30] <- 70
anes08$therm.test.white08[anes08$V085064c==31] <- 69
anes08$therm.test.white08[anes08$V085064c==32] <- 68
anes08$therm.test.white08[anes08$V085064c==33] <- 67
anes08$therm.test.white08[anes08$V085064c==34] <- 66
anes08$therm.test.white08[anes08$V085064c==35] <- 65
anes08$therm.test.white08[anes08$V085064c==36] <- 64
anes08$therm.test.white08[anes08$V085064c==37] <- 63
anes08$therm.test.white08[anes08$V085064c==38] <- 62
anes08$therm.test.white08[anes08$V085064c==39] <- 61
anes08$therm.test.white08[anes08$V085064c==40] <- 60
anes08$therm.test.white08[anes08$V085064c==41] <- 59
anes08$therm.test.white08[anes08$V085064c==42] <- 58
anes08$therm.test.white08[anes08$V085064c==43] <- 57
anes08$therm.test.white08[anes08$V085064c==44] <- 56
anes08$therm.test.white08[anes08$V085064c==45] <- 55
anes08$therm.test.white08[anes08$V085064c==46] <- 54
anes08$therm.test.white08[anes08$V085064c==47] <- 53
anes08$therm.test.white08[anes08$V085064c==48] <- 52
anes08$therm.test.white08[anes08$V085064c==49] <- 51
anes08$therm.test.white08[anes08$V085064c==50] <- 50
anes08$therm.test.white08[anes08$V085064c==51] <- 49
anes08$therm.test.white08[anes08$V085064c==52] <- 48
anes08$therm.test.white08[anes08$V085064c==53] <- 47
anes08$therm.test.white08[anes08$V085064c==54] <- 46
anes08$therm.test.white08[anes08$V085064c==55] <- 45
anes08$therm.test.white08[anes08$V085064c==56] <- 44
anes08$therm.test.white08[anes08$V085064c==57] <- 43
anes08$therm.test.white08[anes08$V085064c==58] <- 42
anes08$therm.test.white08[anes08$V085064c==59] <- 41
anes08$therm.test.white08[anes08$V085064c==60] <- 40
anes08$therm.test.white08[anes08$V085064c==61] <- 39
anes08$therm.test.white08[anes08$V085064c==62] <- 38
anes08$therm.test.white08[anes08$V085064c==63] <- 37
anes08$therm.test.white08[anes08$V085064c==64] <- 36
anes08$therm.test.white08[anes08$V085064c==65] <- 35
anes08$therm.test.white08[anes08$V085064c==66] <- 34
anes08$therm.test.white08[anes08$V085064c==67] <- 33
anes08$therm.test.white08[anes08$V085064c==68] <- 32
anes08$therm.test.white08[anes08$V085064c==69] <- 31
anes08$therm.test.white08[anes08$V085064c==70] <- 30
anes08$therm.test.white08[anes08$V085064c==71] <- 29
anes08$therm.test.white08[anes08$V085064c==72] <- 28
anes08$therm.test.white08[anes08$V085064c==73] <- 27
anes08$therm.test.white08[anes08$V085064c==74] <- 26
anes08$therm.test.white08[anes08$V085064c==75] <- 25
anes08$therm.test.white08[anes08$V085064c==76] <- 24
anes08$therm.test.white08[anes08$V085064c==77] <- 23
anes08$therm.test.white08[anes08$V085064c==78] <- 22
anes08$therm.test.white08[anes08$V085064c==79] <- 21
anes08$therm.test.white08[anes08$V085064c==80] <- 20
anes08$therm.test.white08[anes08$V085064c==81] <- 19
anes08$therm.test.white08[anes08$V085064c==82] <- 18
anes08$therm.test.white08[anes08$V085064c==83] <- 17
anes08$therm.test.white08[anes08$V085064c==84] <- 16
anes08$therm.test.white08[anes08$V085064c==85] <- 15
anes08$therm.test.white08[anes08$V085064c==86] <- 14
anes08$therm.test.white08[anes08$V085064c==87] <- 13
anes08$therm.test.white08[anes08$V085064c==88] <- 12
anes08$therm.test.white08[anes08$V085064c==89] <- 11
anes08$therm.test.white08[anes08$V085064c==90] <- 10
anes08$therm.test.white08[anes08$V085064c==91] <- 9
anes08$therm.test.white08[anes08$V085064c==92] <- 8
anes08$therm.test.white08[anes08$V085064c==93] <- 7
anes08$therm.test.white08[anes08$V085064c==94] <- 6
anes08$therm.test.white08[anes08$V085064c==95] <- 5
anes08$therm.test.white08[anes08$V085064c==96] <- 4
anes08$therm.test.white08[anes08$V085064c==97] <- 3
anes08$therm.test.white08[anes08$V085064c==98] <- 2
anes08$therm.test.white08[anes08$V085064c==99] <- 1
anes08$therm.test.white08[anes08$V085064c==100] <- 0
addmargins(table(anes08$therm.test.white08))

#reverse code white thermometer
anes08$therm.whites08 <- NA
anes08$therm.whites08 <- as.numeric((anes08$therm.test.white08)/100)
addmargins(table(anes08$therm.whites08))

#black racial resentment 1
anes08$rr108 <- NA
anes08$rr108 <- as.numeric(anes08$rr108)
anes08$rr108[anes08$V085143==1] <- 1
anes08$rr108[anes08$V085143==2] <- 0.75
anes08$rr108[anes08$V085143==3] <- 0.5
anes08$rr108[anes08$V085143==4] <- 0.25
anes08$rr108[anes08$V085143==5] <- 0
addmargins(table(anes08$rr108))

#black racial resentment 2
addmargins(table(anes08$V085144))
anes08$rr208 <- NA
anes08$rr208 <- as.numeric(anes08$rr208)
anes08$rr208[anes08$V085144==1] <- 0
anes08$rr208[anes08$V085144==2] <- 0.25
anes08$rr208[anes08$V085144==3] <- 0.5
anes08$rr208[anes08$V085144==4] <- 0.75
anes08$rr208[anes08$V085144==5] <- 1
addmargins(table(anes08$rr208))

#black racial resentment 3
addmargins(table(anes08$V085145))
anes08$rr308 <- NA
anes08$rr308 <- as.numeric(anes08$rr308)
anes08$rr308[anes08$V085145==1] <- 0
anes08$rr308[anes08$V085145==2] <- 0.25
anes08$rr308[anes08$V085145==3] <- 0.5
anes08$rr308[anes08$V085145==4] <- 0.75
anes08$rr308[anes08$V085145==5] <- 1
addmargins(table(anes08$rr308))

#black racial resentment 4
addmargins(table(anes08$V085146))
anes08$rr408 <- NA
anes08$rr408 <- as.numeric(anes08$rr408)
anes08$rr408[anes08$V085146==1] <- 1
anes08$rr408[anes08$V085146==2] <- 0.75
anes08$rr408[anes08$V085146==3] <- 0.5
anes08$rr408[anes08$V085146==4] <- 0.25
anes08$rr408[anes08$V085146==5] <- 0
addmargins(table(anes08$rr408))

#racial resentment recoded and rescaled
anes08$racial.resentment08 <- NA
anes08$racial.resentment08 <- as.numeric(anes08$racial.resentment08)
anes08$racial.resentment08 <- ((anes08$rr108)+(anes08$rr208)+(anes08$rr308)+(anes08$rr408))/4
addmargins(table(anes08$racial.resentment08))

#race
anes08$raceethnicity08 <- NA
anes08$raceethnicity08 <- as.character(anes08$raceethnicity08)
anes08$raceethnicity08[anes08$V083251a==10] <- "2. Black"
anes08$raceethnicity08[anes08$V083251a==20] <- "3. Asian"
anes08$raceethnicity08[anes08$V083251a==30] <- "4. Native"
anes08$raceethnicity08[anes08$V083251a==40] <- "5. Hispanic"
anes08$raceethnicity08[anes08$V083251a==50] <- "1. White"
anes08$raceethnicity08[anes08$V083251a==81] <- "2. Black"
anes08$raceethnicity08[anes08$V083251a==82] <- "3. Asian"
anes08$raceethnicity08[anes08$V083251a==83] <- "4. Native"
anes08$raceethnicity08[anes08$V083251a==84] <- "5. Hispanic"
anes08$raceethnicity08[anes08$V083251a==85] <- "1. White"
anes08$raceethnicity08[anes08$V083251a==90] <- "6. Other"
addmargins(table(anes08$raceethnicity08))  

anes08$white08 <- NA
anes08$white08 <- as.numeric(anes08$white08)
anes08$white08 <- ifelse(anes08$raceethnicity08=="1. White",1,0)
addmargins(table(anes08$white08))

anes08$asian08 <- NA
anes08$asian08 <- as.numeric(anes08$asian08)
anes08$asian08 <- ifelse(anes08$raceethnicity08=="3. Asian",1,0)
addmargins(table(anes08$asian08))

anes08$black08 <- NA
anes08$black08 <- as.numeric(anes08$black08)
anes08$black08 <- ifelse(anes08$raceethnicity08=="2. Black",1,0)
addmargins(table(anes08$black08))

anes08$hispanic08 <- NA
anes08$hispanic08 <- as.numeric(anes08$hispanic08)
anes08$hispanic08 <- ifelse(anes08$raceethnicity08=="5. Hispanic",1,0)
addmargins(table(anes08$hispanic08))

anes08$native08 <- NA
anes08$native08 <- as.numeric(anes08$native08)
anes08$native08 <- ifelse(anes08$raceethnicity08=="4. Native",1,0)
addmargins(table(anes08$native08))

anes08$other08 <- NA
anes08$other08 <- as.numeric(anes08$other08)
anes08$other08 <- ifelse(anes08$raceethnicity08=="6. Other",1,0)
addmargins(table(anes08$other08))

#party identification
anes08$partyid08 <- NA
anes08$partyid08 <- as.numeric(anes08$partyid08)
anes08$partyid08[anes08$V083098x==0] <- 1
anes08$partyid08[anes08$V083098x==1] <- 0.833
anes08$partyid08[anes08$V083098x==2] <- 0.667
anes08$partyid08[anes08$V083098x==3] <- 0.5
anes08$partyid08[anes08$V083098x==4] <- 0.333
anes08$partyid08[anes08$V083098x==5] <- 0.167
anes08$partyid08[anes08$V083098x==6] <- 0
addmargins(table(anes08$partyid08))

#evaluation of economy
anes08$econ.better08 <- NA
anes08$econ.better08 <- as.numeric(anes08$econ.better08)
anes08$econ.better08[anes08$V083057x==1] <- 1
anes08$econ.better08[anes08$V083057x==2] <- 0.75
anes08$econ.better08[anes08$V083057x==3] <- 0.5
anes08$econ.better08[anes08$V083057x==4] <- 0.25
anes08$econ.better08[anes08$V083057x==5] <- 0
addmargins(table(anes08$econ.better08))

#age
anes08$age08 <- NA
anes08$age08 <- as.numeric(anes08$age08)
anes08$age08 <- as.numeric((anes08$V083215x)/100)
anes08$age08[anes08$age08==-0.09|
               anes08$age08==-0.08] <- NA
addmargins(table(anes08$age08))

#gender
anes08$female08 <- NA
anes08$female08 <- as.numeric(anes08$female08)
anes08$female08[anes08$V081101==1] <- 0
anes08$female08[anes08$V081101==2] <- 1
addmargins(table(anes08$female08))

#education
anes08$education08 <- NA
anes08$education08 <- as.numeric(anes08$education08)
anes08$education08[anes08$V083218x==0] <- 0
anes08$education08[anes08$V083218x==1] <- 0.1428571
anes08$education08[anes08$V083218x==2] <- 0.2857143
anes08$education08[anes08$V083218x==3] <- 0.4285714
anes08$education08[anes08$V083218x==4] <- 0.5714286
anes08$education08[anes08$V083218x==5] <- 0.7142857
anes08$education08[anes08$V083218x==6] <- 0.8571429
anes08$education08[anes08$V083216x==7] <- 1
addmargins(table(anes08$education08))

#income
anes08$income08 <- NA
anes08$income08 <- as.numeric(anes08$income08)
anes08$income08[anes08$V083248x==1] <- 0
anes08$income08[anes08$V083248x==2] <- 0.04166667
anes08$income08[anes08$V083248x==3] <- 0.08333333
anes08$income08[anes08$V083248x==4] <- 0.125
anes08$income08[anes08$V083248x==5] <- 0.1666667
anes08$income08[anes08$V083248x==6] <- 0.2083333
anes08$income08[anes08$V083248x==7] <- 0.25
anes08$income08[anes08$V083248x==8] <- 0.2916667
anes08$income08[anes08$V083248x==9] <- 0.3333333
anes08$income08[anes08$V083248x==10] <- 0.375
anes08$income08[anes08$V083248x==11] <- 0.4166667
anes08$income08[anes08$V083248x==12] <- 0.4583333
anes08$income08[anes08$V083248x==13] <- 0.5
anes08$income08[anes08$V083248x==14] <- 0.5416667
anes08$income08[anes08$V083248x==15] <- 0.5833333
anes08$income08[anes08$V083248x==16] <- 0.625
anes08$income08[anes08$V083248x==17] <- 0.6666667
anes08$income08[anes08$V083248x==18] <- 0.7083333
anes08$income08[anes08$V083248x==19] <- 0.75
anes08$income08[anes08$V083248x==20] <- 0.7916667
anes08$income08[anes08$V083248x==21] <- 0.8333333
anes08$income08[anes08$V083248x==22] <- 0.875
anes08$income08[anes08$V083248x==23] <- 0.9166667
anes08$income08[anes08$V083248x==24] <- 0.9583333
anes08$income08[anes08$V083248x==25] <- 1
addmargins(table(anes08$income08))

#religion
addmargins(table(anes08$V083185b))
anes08$protestant08 <- NA
anes08$protestant08 <- as.numeric(anes08$protestant08)
anes08$protestant08[anes08$V083185b==0] <- 0
anes08$protestant08[anes08$V083185b==1] <- 1
anes08$protestant08[anes08$V083185b==2] <- 0
anes08$protestant08[anes08$V083185b==3] <- 0
anes08$protestant08[anes08$V083185b==4] <- 0
anes08$protestant08[anes08$V083185b==5] <- 0
anes08$protestant08[anes08$V083185b==6] <- 0
anes08$protestant08[anes08$V083185b==7] <- 0
anes08$protestant08[anes08$V083185b==8] <- 0
addmargins(table(anes08$protestant08))

#code 2012 data

##CODE ANES 2012

#vote choice 2012 (romney)
anes12$romney.general12 <- NA
anes12$romney.general12 <- as.numeric(anes12$romney.general12)
anes12$romney.general12[anes12$presvote2012_x==1] <- 0
anes12$romney.general12[anes12$presvote2012_x==2] <- 1
anes12$romney.general12[anes12$presvote2012_x==5] <- 0
addmargins(table(anes12$romney.general12))

#race
anes12$raceethnicity12 <- NA
anes12$raceethnicity12 <- as.character(anes12$raceethnicity12)
anes12$raceethnicity12[anes12$dem_raceeth_x==1] <- "1. White"
anes12$raceethnicity12[anes12$dem_raceeth_x==2] <- "2. Black"
anes12$raceethnicity12[anes12$dem_raceeth_x==3] <- "3. Asian"
anes12$raceethnicity12[anes12$dem_raceeth_x==4] <- "4. Native"
anes12$raceethnicity12[anes12$dem_raceeth_x==5] <- "5. Hispanic"
anes12$raceethnicity12[anes12$dem_raceeth_x==6] <- "6. Other"
addmargins(table(anes12$raceethnicity12))

anes12$white12 <- NA
anes12$white12 <- as.numeric(anes12$white12)
anes12$white12 <- ifelse(anes12$raceethnicity12=="1. White",1,0)
addmargins(table(anes12$white12))

anes12$black12 <- NA
anes12$black12 <- as.numeric(anes12$black12)
anes12$black12 <- ifelse(anes12$raceethnicity12=="2. Black",1,0)
addmargins(table(anes12$black12))

anes12$asian12 <- NA
anes12$asian12 <- as.numeric(anes12$asian12)
anes12$asian12 <- ifelse(anes12$raceethnicity12=="3. Asian",1,0)
addmargins(table(anes12$asian12))

anes12$native12 <- NA
anes12$native12 <- as.numeric(anes12$native12)
anes12$native12 <- ifelse(anes12$raceethnicity12=="4. Native",1,0)
addmargins(table(anes12$native12))

anes12$hispanic12 <- NA
anes12$hispanic12 <- as.numeric(anes12$hispanic12)
anes12$hispanic12 <- ifelse(anes12$raceethnicity12=="5. Hispanic",1,0)
addmargins(table(anes12$hispanic12))

anes12$other12 <- NA
anes12$other12 <- as.numeric(anes12$other12)
anes12$other12 <- ifelse(anes12$raceethnicity12=="6. Other",1,0)
addmargins(table(anes12$other12))

#feeling thermometer for asian americans
anes12$therm.test.asian.am12 <- NA
anes12$therm.test.asian.am12 <- as.numeric(anes12$ftcasi_asian)
table(anes12$therm.test.asian.am12)
anes12$therm.test.asian.am12[anes12$ftcasi_asian==-9|
                               anes12$ftcasi_asian==-8|
                               anes12$ftcasi_asian==-7|
                               anes12$ftcasi_asian==-6] <- NA
table(anes12$therm.test.asian.am12)
anes12$therm.test.asian.am12[anes12$ftcasi_asian==0] <- 100
anes12$therm.test.asian.am12[anes12$ftcasi_asian==1] <- 99
anes12$therm.test.asian.am12[anes12$ftcasi_asian==2] <- 98
anes12$therm.test.asian.am12[anes12$ftcasi_asian==3] <- 97
anes12$therm.test.asian.am12[anes12$ftcasi_asian==4] <- 96
anes12$therm.test.asian.am12[anes12$ftcasi_asian==5] <- 95
anes12$therm.test.asian.am12[anes12$ftcasi_asian==6] <- 94
anes12$therm.test.asian.am12[anes12$ftcasi_asian==7] <- 93
anes12$therm.test.asian.am12[anes12$ftcasi_asian==8] <- 92
anes12$therm.test.asian.am12[anes12$ftcasi_asian==9] <- 91
anes12$therm.test.asian.am12[anes12$ftcasi_asian==10] <- 90
anes12$therm.test.asian.am12[anes12$ftcasi_asian==11] <- 89
anes12$therm.test.asian.am12[anes12$ftcasi_asian==12] <- 88
anes12$therm.test.asian.am12[anes12$ftcasi_asian==13] <- 87
anes12$therm.test.asian.am12[anes12$ftcasi_asian==14] <- 86
anes12$therm.test.asian.am12[anes12$ftcasi_asian==15] <- 85
anes12$therm.test.asian.am12[anes12$ftcasi_asian==16] <- 84
anes12$therm.test.asian.am12[anes12$ftcasi_asian==17] <- 83
anes12$therm.test.asian.am12[anes12$ftcasi_asian==18] <- 82
anes12$therm.test.asian.am12[anes12$ftcasi_asian==19] <- 81
anes12$therm.test.asian.am12[anes12$ftcasi_asian==20] <- 80
anes12$therm.test.asian.am12[anes12$ftcasi_asian==21] <- 79
anes12$therm.test.asian.am12[anes12$ftcasi_asian==22] <- 78
anes12$therm.test.asian.am12[anes12$ftcasi_asian==23] <- 77
anes12$therm.test.asian.am12[anes12$ftcasi_asian==24] <- 76
anes12$therm.test.asian.am12[anes12$ftcasi_asian==25] <- 75
anes12$therm.test.asian.am12[anes12$ftcasi_asian==26] <- 74
anes12$therm.test.asian.am12[anes12$ftcasi_asian==27] <- 73
anes12$therm.test.asian.am12[anes12$ftcasi_asian==28] <- 72
anes12$therm.test.asian.am12[anes12$ftcasi_asian==29] <- 71
anes12$therm.test.asian.am12[anes12$ftcasi_asian==30] <- 70
anes12$therm.test.asian.am12[anes12$ftcasi_asian==31] <- 69
anes12$therm.test.asian.am12[anes12$ftcasi_asian==32] <- 68
anes12$therm.test.asian.am12[anes12$ftcasi_asian==33] <- 67
anes12$therm.test.asian.am12[anes12$ftcasi_asian==34] <- 66
anes12$therm.test.asian.am12[anes12$ftcasi_asian==35] <- 65
anes12$therm.test.asian.am12[anes12$ftcasi_asian==36] <- 64
anes12$therm.test.asian.am12[anes12$ftcasi_asian==37] <- 63
anes12$therm.test.asian.am12[anes12$ftcasi_asian==38] <- 62
anes12$therm.test.asian.am12[anes12$ftcasi_asian==39] <- 61
anes12$therm.test.asian.am12[anes12$ftcasi_asian==40] <- 60
anes12$therm.test.asian.am12[anes12$ftcasi_asian==41] <- 59
anes12$therm.test.asian.am12[anes12$ftcasi_asian==42] <- 58
anes12$therm.test.asian.am12[anes12$ftcasi_asian==43] <- 57
anes12$therm.test.asian.am12[anes12$ftcasi_asian==44] <- 56
anes12$therm.test.asian.am12[anes12$ftcasi_asian==45] <- 55
anes12$therm.test.asian.am12[anes12$ftcasi_asian==46] <- 54
anes12$therm.test.asian.am12[anes12$ftcasi_asian==47] <- 53
anes12$therm.test.asian.am12[anes12$ftcasi_asian==48] <- 52
anes12$therm.test.asian.am12[anes12$ftcasi_asian==49] <- 51
anes12$therm.test.asian.am12[anes12$ftcasi_asian==50] <- 50
anes12$therm.test.asian.am12[anes12$ftcasi_asian==51] <- 49
anes12$therm.test.asian.am12[anes12$ftcasi_asian==52] <- 48
anes12$therm.test.asian.am12[anes12$ftcasi_asian==53] <- 47
anes12$therm.test.asian.am12[anes12$ftcasi_asian==54] <- 46
anes12$therm.test.asian.am12[anes12$ftcasi_asian==55] <- 45
anes12$therm.test.asian.am12[anes12$ftcasi_asian==56] <- 44
anes12$therm.test.asian.am12[anes12$ftcasi_asian==57] <- 43
anes12$therm.test.asian.am12[anes12$ftcasi_asian==58] <- 42
anes12$therm.test.asian.am12[anes12$ftcasi_asian==59] <- 41
anes12$therm.test.asian.am12[anes12$ftcasi_asian==60] <- 40
anes12$therm.test.asian.am12[anes12$ftcasi_asian==61] <- 39
anes12$therm.test.asian.am12[anes12$ftcasi_asian==62] <- 38
anes12$therm.test.asian.am12[anes12$ftcasi_asian==63] <- 37
anes12$therm.test.asian.am12[anes12$ftcasi_asian==64] <- 36
anes12$therm.test.asian.am12[anes12$ftcasi_asian==65] <- 35
anes12$therm.test.asian.am12[anes12$ftcasi_asian==66] <- 34
anes12$therm.test.asian.am12[anes12$ftcasi_asian==67] <- 33
anes12$therm.test.asian.am12[anes12$ftcasi_asian==68] <- 32
anes12$therm.test.asian.am12[anes12$ftcasi_asian==69] <- 31
anes12$therm.test.asian.am12[anes12$ftcasi_asian==70] <- 30
anes12$therm.test.asian.am12[anes12$ftcasi_asian==71] <- 29
anes12$therm.test.asian.am12[anes12$ftcasi_asian==72] <- 28
anes12$therm.test.asian.am12[anes12$ftcasi_asian==73] <- 27
anes12$therm.test.asian.am12[anes12$ftcasi_asian==74] <- 26
anes12$therm.test.asian.am12[anes12$ftcasi_asian==75] <- 25
anes12$therm.test.asian.am12[anes12$ftcasi_asian==76] <- 24
anes12$therm.test.asian.am12[anes12$ftcasi_asian==77] <- 23
anes12$therm.test.asian.am12[anes12$ftcasi_asian==78] <- 22
anes12$therm.test.asian.am12[anes12$ftcasi_asian==79] <- 21
anes12$therm.test.asian.am12[anes12$ftcasi_asian==80] <- 20
anes12$therm.test.asian.am12[anes12$ftcasi_asian==81] <- 19
anes12$therm.test.asian.am12[anes12$ftcasi_asian==82] <- 18
anes12$therm.test.asian.am12[anes12$ftcasi_asian==83] <- 17
anes12$therm.test.asian.am12[anes12$ftcasi_asian==84] <- 16
anes12$therm.test.asian.am12[anes12$ftcasi_asian==85] <- 15
anes12$therm.test.asian.am12[anes12$ftcasi_asian==86] <- 14
anes12$therm.test.asian.am12[anes12$ftcasi_asian==87] <- 13
anes12$therm.test.asian.am12[anes12$ftcasi_asian==88] <- 12
anes12$therm.test.asian.am12[anes12$ftcasi_asian==89] <- 11
anes12$therm.test.asian.am12[anes12$ftcasi_asian==90] <- 10
anes12$therm.test.asian.am12[anes12$ftcasi_asian==91] <- 9
anes12$therm.test.asian.am12[anes12$ftcasi_asian==92] <- 8
anes12$therm.test.asian.am12[anes12$ftcasi_asian==93] <- 7
anes12$therm.test.asian.am12[anes12$ftcasi_asian==94] <- 6
anes12$therm.test.asian.am12[anes12$ftcasi_asian==95] <- 5
anes12$therm.test.asian.am12[anes12$ftcasi_asian==96] <- 4
anes12$therm.test.asian.am12[anes12$ftcasi_asian==97] <- 3
anes12$therm.test.asian.am12[anes12$ftcasi_asian==98] <- 2
anes12$therm.test.asian.am12[anes12$ftcasi_asian==99] <- 1
anes12$therm.test.asian.am12[anes12$ftcasi_asian==100] <- 0
addmargins(table(anes12$therm.test.asian.am12))

#feeling thermometer asian americans recoded and rescaled
anes12$therm.asian.americans12 <- NA
anes12$therm.asian.americans12 <- as.numeric((anes12$therm.test.asian.am12)/100)
addmargins(table(anes12$therm.asian.americans12))

#feeling thermometer hispanic
anes12$therm.test.hispanic12 <- NA
anes12$therm.test.hispanic12 <- as.numeric(anes12$ftcasi_hisp)
table(anes12$therm.test.hispanic12)
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==-9|
                               anes12$ftcasi_hisp==-8|
                               anes12$ftcasi_hisp==-7|
                               anes12$ftcasi_hisp==-6] <- NA
table(anes12$therm.test.hispanic12)
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==0] <- 100
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==1] <- 99
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==2] <- 98
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==3] <- 97
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==4] <- 96
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==5] <- 95
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==6] <- 94
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==7] <- 93
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==8] <- 92
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==9] <- 91
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==10] <- 90
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==11] <- 89
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==12] <- 88
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==13] <- 87
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==14] <- 86
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==15] <- 85
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==16] <- 84
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==17] <- 83
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==18] <- 82
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==19] <- 81
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==20] <- 80
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==21] <- 79
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==22] <- 78
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==23] <- 77
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==24] <- 76
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==25] <- 75
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==26] <- 74
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==27] <- 73
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==28] <- 72
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==29] <- 71
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==30] <- 70
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==31] <- 69
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==32] <- 68
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==33] <- 67
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==34] <- 66
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==35] <- 65
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==36] <- 64
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==37] <- 63
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==38] <- 62
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==39] <- 61
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==40] <- 60
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==41] <- 59
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==42] <- 58
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==43] <- 57
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==44] <- 56
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==45] <- 55
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==46] <- 54
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==47] <- 53
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==48] <- 52
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==49] <- 51
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==50] <- 50
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==51] <- 49
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==52] <- 48
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==53] <- 47
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==54] <- 46
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==55] <- 45
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==56] <- 44
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==57] <- 43
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==58] <- 42
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==59] <- 41
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==60] <- 40
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==61] <- 39
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==62] <- 38
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==63] <- 37
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==64] <- 36
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==65] <- 35
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==66] <- 34
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==67] <- 33
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==68] <- 32
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==69] <- 31
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==70] <- 30
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==71] <- 29
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==72] <- 28
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==73] <- 27
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==74] <- 26
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==75] <- 25
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==76] <- 24
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==77] <- 23
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==78] <- 22
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==79] <- 21
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==80] <- 20
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==81] <- 19
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==82] <- 18
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==83] <- 17
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==84] <- 16
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==85] <- 15
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==86] <- 14
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==87] <- 13
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==88] <- 12
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==89] <- 11
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==90] <- 10
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==91] <- 9
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==92] <- 8
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==93] <- 7
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==94] <- 6
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==95] <- 5
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==96] <- 4
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==97] <- 3
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==98] <- 2
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==99] <- 1
anes12$therm.test.hispanic12[anes12$ftcasi_hisp==100] <- 0
addmargins(table(anes12$therm.test.hispanic12))

#hispanic thermometer re-coded and rescaled
anes12$therm.hispanics12 <- NA
anes12$therm.hispanics12 <- as.numeric((anes12$therm.test.hispanic12)/100)
addmargins(table(anes12$therm.hispanics12))

#feeling thermometer whites
addmargins(table(anes12$ftcasi_white))
anes12$therm.test.white12 <- NA
anes12$therm.test.white12 <- as.numeric(anes12$ftcasi_white)
table(anes12$therm.test.white12)
anes12$therm.test.white12[anes12$ftcasi_white==-9|
                            anes12$ftcasi_white==-8|
                            anes12$ftcasi_white==-7|
                            anes12$ftcasi_white==-6] <- NA
table(anes12$therm.test.white12)
anes12$therm.test.white12[anes12$ftcasi_white==0] <- 100
anes12$therm.test.white12[anes12$ftcasi_white==1] <- 99
anes12$therm.test.white12[anes12$ftcasi_white==2] <- 98
anes12$therm.test.white12[anes12$ftcasi_white==3] <- 97
anes12$therm.test.white12[anes12$ftcasi_white==4] <- 96
anes12$therm.test.white12[anes12$ftcasi_white==5] <- 95
anes12$therm.test.white12[anes12$ftcasi_white==6] <- 94
anes12$therm.test.white12[anes12$ftcasi_white==7] <- 93
anes12$therm.test.white12[anes12$ftcasi_white==8] <- 92
anes12$therm.test.white12[anes12$ftcasi_white==9] <- 91
anes12$therm.test.white12[anes12$ftcasi_white==10] <- 90
anes12$therm.test.white12[anes12$ftcasi_white==11] <- 89
anes12$therm.test.white12[anes12$ftcasi_white==12] <- 88
anes12$therm.test.white12[anes12$ftcasi_white==13] <- 87
anes12$therm.test.white12[anes12$ftcasi_white==14] <- 86
anes12$therm.test.white12[anes12$ftcasi_white==15] <- 85
anes12$therm.test.white12[anes12$ftcasi_white==16] <- 84
anes12$therm.test.white12[anes12$ftcasi_white==17] <- 83
anes12$therm.test.white12[anes12$ftcasi_white==18] <- 82
anes12$therm.test.white12[anes12$ftcasi_white==19] <- 81
anes12$therm.test.white12[anes12$ftcasi_white==20] <- 80
anes12$therm.test.white12[anes12$ftcasi_white==21] <- 79
anes12$therm.test.white12[anes12$ftcasi_white==22] <- 78
anes12$therm.test.white12[anes12$ftcasi_white==23] <- 77
anes12$therm.test.white12[anes12$ftcasi_white==24] <- 76
anes12$therm.test.white12[anes12$ftcasi_white==25] <- 75
anes12$therm.test.white12[anes12$ftcasi_white==26] <- 74
anes12$therm.test.white12[anes12$ftcasi_white==27] <- 73
anes12$therm.test.white12[anes12$ftcasi_white==28] <- 72
anes12$therm.test.white12[anes12$ftcasi_white==29] <- 71
anes12$therm.test.white12[anes12$ftcasi_white==30] <- 70
anes12$therm.test.white12[anes12$ftcasi_white==31] <- 69
anes12$therm.test.white12[anes12$ftcasi_white==32] <- 68
anes12$therm.test.white12[anes12$ftcasi_white==33] <- 67
anes12$therm.test.white12[anes12$ftcasi_white==34] <- 66
anes12$therm.test.white12[anes12$ftcasi_white==35] <- 65
anes12$therm.test.white12[anes12$ftcasi_white==36] <- 64
anes12$therm.test.white12[anes12$ftcasi_white==37] <- 63
anes12$therm.test.white12[anes12$ftcasi_white==38] <- 62
anes12$therm.test.white12[anes12$ftcasi_white==39] <- 61
anes12$therm.test.white12[anes12$ftcasi_white==40] <- 60
anes12$therm.test.white12[anes12$ftcasi_white==41] <- 59
anes12$therm.test.white12[anes12$ftcasi_white==42] <- 58
anes12$therm.test.white12[anes12$ftcasi_white==43] <- 57
anes12$therm.test.white12[anes12$ftcasi_white==44] <- 56
anes12$therm.test.white12[anes12$ftcasi_white==45] <- 55
anes12$therm.test.white12[anes12$ftcasi_white==46] <- 54
anes12$therm.test.white12[anes12$ftcasi_white==47] <- 53
anes12$therm.test.white12[anes12$ftcasi_white==48] <- 52
anes12$therm.test.white12[anes12$ftcasi_white==49] <- 51
anes12$therm.test.white12[anes12$ftcasi_white==50] <- 50
anes12$therm.test.white12[anes12$ftcasi_white==51] <- 49
anes12$therm.test.white12[anes12$ftcasi_white==52] <- 48
anes12$therm.test.white12[anes12$ftcasi_white==53] <- 47
anes12$therm.test.white12[anes12$ftcasi_white==54] <- 46
anes12$therm.test.white12[anes12$ftcasi_white==55] <- 45
anes12$therm.test.white12[anes12$ftcasi_white==56] <- 44
anes12$therm.test.white12[anes12$ftcasi_white==57] <- 43
anes12$therm.test.white12[anes12$ftcasi_white==58] <- 42
anes12$therm.test.white12[anes12$ftcasi_white==59] <- 41
anes12$therm.test.white12[anes12$ftcasi_white==60] <- 40
anes12$therm.test.white12[anes12$ftcasi_white==61] <- 39
anes12$therm.test.white12[anes12$ftcasi_white==62] <- 38
anes12$therm.test.white12[anes12$ftcasi_white==63] <- 37
anes12$therm.test.white12[anes12$ftcasi_white==64] <- 36
anes12$therm.test.white12[anes12$ftcasi_white==65] <- 35
anes12$therm.test.white12[anes12$ftcasi_white==66] <- 34
anes12$therm.test.white12[anes12$ftcasi_white==67] <- 33
anes12$therm.test.white12[anes12$ftcasi_white==68] <- 32
anes12$therm.test.white12[anes12$ftcasi_white==69] <- 31
anes12$therm.test.white12[anes12$ftcasi_white==70] <- 30
anes12$therm.test.white12[anes12$ftcasi_white==71] <- 29
anes12$therm.test.white12[anes12$ftcasi_white==72] <- 28
anes12$therm.test.white12[anes12$ftcasi_white==73] <- 27
anes12$therm.test.white12[anes12$ftcasi_white==74] <- 26
anes12$therm.test.white12[anes12$ftcasi_white==75] <- 25
anes12$therm.test.white12[anes12$ftcasi_white==76] <- 24
anes12$therm.test.white12[anes12$ftcasi_white==77] <- 23
anes12$therm.test.white12[anes12$ftcasi_white==78] <- 22
anes12$therm.test.white12[anes12$ftcasi_white==79] <- 21
anes12$therm.test.white12[anes12$ftcasi_white==80] <- 20
anes12$therm.test.white12[anes12$ftcasi_white==81] <- 19
anes12$therm.test.white12[anes12$ftcasi_white==82] <- 18
anes12$therm.test.white12[anes12$ftcasi_white==83] <- 17
anes12$therm.test.white12[anes12$ftcasi_white==84] <- 16
anes12$therm.test.white12[anes12$ftcasi_white==85] <- 15
anes12$therm.test.white12[anes12$ftcasi_white==86] <- 14
anes12$therm.test.white12[anes12$ftcasi_white==87] <- 13
anes12$therm.test.white12[anes12$ftcasi_white==88] <- 12
anes12$therm.test.white12[anes12$ftcasi_white==89] <- 11
anes12$therm.test.white12[anes12$ftcasi_white==90] <- 10
anes12$therm.test.white12[anes12$ftcasi_white==91] <- 9
anes12$therm.test.white12[anes12$ftcasi_white==92] <- 8
anes12$therm.test.white12[anes12$ftcasi_white==93] <- 7
anes12$therm.test.white12[anes12$ftcasi_white==94] <- 6
anes12$therm.test.white12[anes12$ftcasi_white==95] <- 5
anes12$therm.test.white12[anes12$ftcasi_white==96] <- 4
anes12$therm.test.white12[anes12$ftcasi_white==97] <- 3
anes12$therm.test.white12[anes12$ftcasi_white==98] <- 2
anes12$therm.test.white12[anes12$ftcasi_white==99] <- 1
anes12$therm.test.white12[anes12$ftcasi_white==100] <- 0
addmargins(table(anes12$therm.test.white12))

#white feeling thermometer re-coded and re-scaled
anes12$therm.whites12 <- NA
anes12$therm.whites12 <- as.numeric(anes12$ftcasi_white)/100
anes12$therm.whites12[anes12$therm.whites12==-0.09|
                        anes12$therm.whites12==-0.08|
                        anes12$therm.whites12==-0.07|
                        anes12$therm.whites12==-0.06] <- NA
addmargins(table(anes12$therm.whites12))

#black racial resentment 1
anes12$rr112 <- NA
anes12$rr112 <- as.numeric(anes12$rr112)
anes12$rr112[anes12$resent_workway==1] <- 1
anes12$rr112[anes12$resent_workway==2] <- 0.75
anes12$rr112[anes12$resent_workway==3] <- 0.5
anes12$rr112[anes12$resent_workway==4] <- 0.25
anes12$rr112[anes12$resent_workway==5] <- 0
addmargins(table(anes12$rr112))

#black racial resentment 2
anes12$rr212 <- NA
anes12$rr212 <- as.numeric(anes12$rr212)
anes12$rr212[anes12$resent_slavery==1] <- 0
anes12$rr212[anes12$resent_slavery==2] <- 0.25
anes12$rr212[anes12$resent_slavery==3] <- 0.5
anes12$rr212[anes12$resent_slavery==4] <- 0.75
anes12$rr212[anes12$resent_slavery==5] <- 1
addmargins(table(anes12$rr212))

#black racial resentment 3
anes12$rr312 <- NA
anes12$rr312 <- as.numeric(anes12$rr312)
anes12$rr312[anes12$resent_deserve==1] <- 0
anes12$rr312[anes12$resent_deserve==2] <- 0.25
anes12$rr312[anes12$resent_deserve==3] <- 0.5
anes12$rr312[anes12$resent_deserve==4] <- 0.75
anes12$rr312[anes12$resent_deserve==5] <- 1
addmargins(table(anes12$rr312))

#black racial resentment 4
anes12$rr412 <- NA
anes12$rr412 <- as.numeric(anes12$rr412)
anes12$rr412[anes12$resent_try==1] <- 1
anes12$rr412[anes12$resent_try==2] <- 0.75
anes12$rr412[anes12$resent_try==3] <- 0.5
anes12$rr412[anes12$resent_try==4] <- 0.25
anes12$rr412[anes12$resent_try==5] <- 0
addmargins(table(anes12$rr412))

#black racial resentment recoded and rescaled
anes12$racial.resentment12 <- NA
anes12$racial.resentment12 <- as.numeric(anes12$racial.resentment12)
anes12$racial.resentment12 <- ((anes12$rr112)+(anes12$rr212)+(anes12$rr312)+(anes12$rr412))/4
addmargins(table(anes12$racial.resentment12))

#partisanship
anes12$partyid12 <- NA
anes12$partyid12 <- as.numeric(anes12$partyid12)
anes12$partyid12[anes12$pid_x==1] <- 1
anes12$partyid12[anes12$pid_x==2] <- 0.833
anes12$partyid12[anes12$pid_x==3] <- 0.667
anes12$partyid12[anes12$pid_x==4] <- 0.5
anes12$partyid12[anes12$pid_x==5] <- 0.333
anes12$partyid12[anes12$pid_x==6] <- 0.167
anes12$partyid12[anes12$pid_x==7] <- 0
addmargins(table(anes12$partyid12))

#evaluation of economy
addmargins(table(anes12$finance_finpast_x))
anes12$econ.better12 <- NA
anes12$econ.better12 <- as.numeric(anes12$econ.better12)
anes12$econ.better12[anes12$finance_finpast_x==1] <- 1
anes12$econ.better12[anes12$finance_finpast_x==2] <- 0.75
anes12$econ.better12[anes12$finance_finpast_x==3] <- 0.5
anes12$econ.better12[anes12$finance_finpast_x==4] <- 0.25
anes12$econ.better12[anes12$finance_finpast_x==5] <- 0
addmargins(table(anes12$econ.better12))

#age
anes12$age12 <- NA
anes12$age12 <- as.numeric(anes12$age12)
anes12$age12 <- as.numeric(((anes12$dem_age_r_x)/100))
anes12$age12[anes12$age12==-0.02] <- NA
addmargins(table(anes12$age12))
str(anes12$age12)

#female
anes12$female12 <- NA
anes12$female12 <- as.numeric(anes12$female12)
anes12$female12[anes12$gender_respondent_x==1] <- 0
anes12$female12[anes12$gender_respondent_x==2] <- 1
addmargins(table(anes12$female12))

#education
anes12$education12 <- NA
anes12$education12 <- as.numeric(anes12$education12)
anes12$education12[anes12$dem_edugroup_x==1] <- 0
anes12$education12[anes12$dem_edugroup_x==2] <- 0.25
anes12$education12[anes12$dem_edugroup_x==3] <- 0.5
anes12$education12[anes12$dem_edugroup_x==4] <- 0.75
anes12$education12[anes12$dem_edugroup_x==5] <- 1
addmargins(table(anes12$education12))

#income
anes12$income12 <- NA
anes12$income12 <- as.numeric(anes12$income12)
anes12$income12[anes12$inc_incgroup_pre==1] <- 0
anes12$income12[anes12$inc_incgroup_pre==2] <- 0.03703704
anes12$income12[anes12$inc_incgroup_pre==3] <- 0.07407407
anes12$income12[anes12$inc_incgroup_pre==4] <- 0.1111111
anes12$income12[anes12$inc_incgroup_pre==5] <- 0.1481481
anes12$income12[anes12$inc_incgroup_pre==6] <- 0.1851852
anes12$income12[anes12$inc_incgroup_pre==7] <- 0.2222222
anes12$income12[anes12$inc_incgroup_pre==8] <- 0.2592593
anes12$income12[anes12$inc_incgroup_pre==9] <- 0.2962963
anes12$income12[anes12$inc_incgroup_pre==10] <- 0.3333333
anes12$income12[anes12$inc_incgroup_pre==11] <- 0.3703704
anes12$income12[anes12$inc_incgroup_pre==12] <- 0.4074074
anes12$income12[anes12$inc_incgroup_pre==13] <- 0.4444444
anes12$income12[anes12$inc_incgroup_pre==14] <- 0.4814815
anes12$income12[anes12$inc_incgroup_pre==15] <- 0.5185185
anes12$income12[anes12$inc_incgroup_pre==16] <- 0.5555556
anes12$income12[anes12$inc_incgroup_pre==17] <- 0.5925926
anes12$income12[anes12$inc_incgroup_pre==18] <- 0.6296296
anes12$income12[anes12$inc_incgroup_pre==19] <- 0.6666667
anes12$income12[anes12$inc_incgroup_pre==20] <- 0.7037037
anes12$income12[anes12$inc_incgroup_pre==21] <- 0.7407407
anes12$income12[anes12$inc_incgroup_pre==22] <- 0.7777778
anes12$income12[anes12$inc_incgroup_pre==23] <- 0.8148148
anes12$income12[anes12$inc_incgroup_pre==24] <- 0.8518519
anes12$income12[anes12$inc_incgroup_pre==25] <- 0.8888889
anes12$income12[anes12$inc_incgroup_pre==26] <- 0.9259259
anes12$income12[anes12$inc_incgroup_pre==27] <- 0.962963
anes12$income12[anes12$inc_incgroup_pre==28] <- 1
addmargins(table(anes12$income12))

#protestant
anes12$protestant12 <- NA
anes12$protestant12 <- as.numeric(anes12$protestant12)
anes12$protestant12[anes12$relig_7cat_x==1] <- 1
anes12$protestant12[anes12$relig_7cat_x==2] <- 1
anes12$protestant12[anes12$relig_7cat_x==3] <- 1
anes12$protestant12[anes12$relig_7cat_x==4] <- 0
anes12$protestant12[anes12$relig_7cat_x==5] <- 0
anes12$protestant12[anes12$relig_7cat_x==6] <- 0
anes12$protestant12[anes12$relig_7cat_x==7] <- 0
anes12$protestant12[anes12$relig_7cat_x==8] <- 0
addmargins(table(anes12$protestant12))


#re-code 2016 data 

##CODE ANES 2016

#partisanship
anes16$partyid16 <- NA
anes16$partyid16 <- as.numeric(anes16$partyid16)
anes16$partyid16[anes16$V161158x==1] <- 1
anes16$partyid16[anes16$V161158x==2] <- 0.833
anes16$partyid16[anes16$V161158x==3] <- 0.667
anes16$partyid16[anes16$V161158x==4] <- 0.5
anes16$partyid16[anes16$V161158x==5] <- 0.333
anes16$partyid16[anes16$V161158x==6] <- 0.167
anes16$partyid16[anes16$V161158x==7] <- 0
table(anes16$partyid16)

### RELIGIOUS AFFILIATION (pre)
anes16$protestant16 <- NA
anes16$protestant16 <- as.numeric(anes16$protestant16)
anes16$protestant16[anes16$V161265x==1] <-1 
anes16$protestant16[anes16$V161265x==2] <-1 
anes16$protestant16[anes16$V161265x==3] <-0 
anes16$protestant16[anes16$V161265x==4] <-0 
anes16$protestant16[anes16$V161265x==5] <-0 
anes16$protestant16[anes16$V161265x==6] <-0 
anes16$protestant16[anes16$V161265x==7] <-0 
anes16$protestant16[anes16$V161265x==8] <-0 
addmargins(table(anes16$protestant16))

## AGE
anes16$age.uncleaned <- NA
anes16$age.uncleaned <- as.numeric(anes16$V161267c)
anes16$age.uncleaned[anes16$V161267c==-9|
                       anes16$V161267c==-8] <- NA
addmargins(table(anes16$age.uncleaned))

anes16$age.uncleaned.uncleaned <- NA
anes16$age.uncleaned.uncleaned <- as.numeric((2016-(anes16$age.uncleaned)))
addmargins(table(anes16$age.uncleaned.uncleaned))

anes16$age16 <- NA
anes16$age16 <- as.numeric((anes16$age.uncleaned.uncleaned)/100)
addmargins(table(anes16$age16))
str(anes16$age16)

##EDUCATION
anes16$education16 <- NA
anes16$education16 <- as.numeric(anes16$education16)
anes16$education16[anes16$V161270==1] <- 0
anes16$education16[anes16$V161270==2] <- 0.067
anes16$education16[anes16$V161270==3] <- 0.133
anes16$education16[anes16$V161270==4] <- 0.2
anes16$education16[anes16$V161270==5] <- 0.267
anes16$education16[anes16$V161270==6] <- 0.333
anes16$education16[anes16$V161270==7] <- 0.4
anes16$education16[anes16$V161270==8] <- 0.467
anes16$education16[anes16$V161270==9|anes16$V161270==90] <- 0.533
anes16$education16[anes16$V161270==10] <- 0.6
anes16$education16[anes16$V161270==11] <- 0.667
anes16$education16[anes16$V161270==12] <- 0.733
anes16$education16[anes16$V161270==13] <- 0.8
anes16$education16[anes16$V161270==14] <- 0.867
anes16$education16[anes16$V161270==15] <- 0.933
anes16$education16[anes16$V161270==16] <- 1
addmargins(table(anes16$education16))

## RACE
anes16$raceethnicity16 <- NA
anes16$raceethnicity16 <- as.character(anes16$raceethnicity16)
anes16$raceethnicity16[anes16$V161310x==1] <- "1. White" 
anes16$raceethnicity16[anes16$V161310x==2] <- "2. Black" 
anes16$raceethnicity16[anes16$V161310x==3] <- "3. Asian" 
anes16$raceethnicity16[anes16$V161310x==4] <- "4. Native"
anes16$raceethnicity16[anes16$V161310x==5] <- "5. Hispanic" 
anes16$raceethnicity16[anes16$V161310x==6] <- "6. Other"
addmargins(table(anes16$raceethnicity16))

anes16$white16 <- NA
anes16$white16 <- as.numeric(anes16$white16)
anes16$white16 <- ifelse(anes16$raceethnicity16=="1. White",1,0)
addmargins(table(anes16$white16))

anes16$black16 <- NA
anes16$black16 <- as.numeric(anes16$black16)
anes16$black16 <- ifelse(anes16$raceethnicity16=="2. Black",1,0)
addmargins(table(anes16$black16))

anes16$asian16 <- NA
anes16$asian16 <- as.numeric(anes16$asian16)
anes16$asian16 <- ifelse(anes16$raceethnicity16=="3. Asian",1,0)
addmargins(table(anes16$asian16))

anes16$native16 <- NA
anes16$native16 <- as.numeric(anes16$native16)
anes16$native16 <- ifelse(anes16$raceethnicity16=="4. Native",1,0)
addmargins(table(anes16$native16))

anes16$hispanic16 <- NA
anes16$hispanic16 <- as.numeric(anes16$hispanic16)
anes16$hispanic16 <- ifelse(anes16$raceethnicity16=="5. Hispanic",1,0)
addmargins(table(anes16$hispanic16))

anes16$other16 <- NA
anes16$other16 <- as.numeric(anes16$other16)
anes16$other16 <- ifelse(anes16$raceethnicity16=="6. Other",1,0)
addmargins(table(anes16$other16))


##INCOME
anes16$income16 <- NA
anes16$income16 <- as.numeric(anes16$income16)
anes16$income16[anes16$V161361x==1] <- 0
anes16$income16[anes16$V161361x==2] <- 0.03703704
anes16$income16[anes16$V161361x==3] <- 0.07407407
anes16$income16[anes16$V161361x==4] <- 0.1111111
anes16$income16[anes16$V161361x==5] <- 0.1481481
anes16$income16[anes16$V161361x==6] <- 0.1851852
anes16$income16[anes16$V161361x==7] <- 0.2222222
anes16$income16[anes16$V161361x==8] <- 0.2592593
anes16$income16[anes16$V161361x==9] <- 0.2962963
anes16$income16[anes16$V161361x==10] <- 0.3333333
anes16$income16[anes16$V161361x==11] <- 0.3703704
anes16$income16[anes16$V161361x==12] <- 0.4074074
anes16$income16[anes16$V161361x==13] <- 0.4444444
anes16$income16[anes16$V161361x==14] <- 0.4814815
anes16$income16[anes16$V161361x==15] <- 0.5185185
anes16$income16[anes16$V161361x==16] <- 0.5555556
anes16$income16[anes16$V161361x==17] <- 0.5925926
anes16$income16[anes16$V161361x==18] <- 0.6296296
anes16$income16[anes16$V161361x==19] <- 0.6666667
anes16$income16[anes16$V161361x==20] <- 0.7037037
anes16$income16[anes16$V161361x==21] <- 0.7407407
anes16$income16[anes16$V161361x==22] <- 0.7777778
anes16$income16[anes16$V161361x==23] <- 0.8148148
anes16$income16[anes16$V161361x==24] <- 0.8518519
anes16$income16[anes16$V161361x==25] <- 0.8888889
anes16$income16[anes16$V161361x==26] <- 0.9259259
anes16$income16[anes16$V161361x==27] <- 0.962963
anes16$income16[anes16$V161361x==28] <- 1
addmargins(table(anes16$income16))

##2016 VOICE CHOICE (trump)
anes16$trump.general16 <- NA
anes16$trump.general16 <- as.numeric(anes16$trump.general16)
anes16$trump.general16[anes16$V162062x==1] <- 0
anes16$trump.general16[anes16$V162062x==2] <- 1
anes16$trump.general16[anes16$V162062x==3] <- 0
anes16$trump.general16[anes16$V162062x==4] <- 0
anes16$trump.general16[anes16$V162062x==5] <- 0
addmargins(table(anes16$trump.general16))

#black racial resentment 1
anes16$rr116 <- NA
anes16$rr116 <- as.numeric(anes16$rr116)
anes16$rr116[anes16$V162211==1] <- 1
anes16$rr116[anes16$V162211==2] <- 0.75
anes16$rr116[anes16$V162211==3] <- 0.5
anes16$rr116[anes16$V162211==4] <- 0.25
anes16$rr116[anes16$V162211==5] <- 0
addmargins(table(anes16$rr116))  

#black racial resentment 2
anes16$rr216 <- NA
anes16$rr216 <- as.numeric(anes16$rr216)
anes16$rr216[anes16$V162212==1] <- 0
anes16$rr216[anes16$V162212==2] <- 0.25
anes16$rr216[anes16$V162212==3] <- 0.5
anes16$rr216[anes16$V162212==4] <- 0.75
anes16$rr216[anes16$V162212==5] <- 1
addmargins(table(anes16$rr216))  

#black racial resentment 3
anes16$rr316 <- NA
anes16$rr316 <- as.numeric(anes16$rr316)
anes16$rr316[anes16$V162213==1] <- 0
anes16$rr316[anes16$V162213==2] <- 0.25
anes16$rr316[anes16$V162213==3] <- 0.5
anes16$rr316[anes16$V162213==4] <- 0.75
anes16$rr316[anes16$V162213==5] <- 1
addmargins(table(anes16$rr316))  

#black racial resentment 4
anes16$rr416 <- NA
anes16$rr416 <- as.numeric(anes16$rr416)
anes16$rr416[anes16$V162214==1] <- 1
anes16$rr416[anes16$V162214==2] <- 0.75
anes16$rr416[anes16$V162214==3] <- 0.5
anes16$rr416[anes16$V162214==4] <- 0.25
anes16$rr416[anes16$V162214==5] <- 0
addmargins(table(anes16$rr416))

#black racial resentment recoded and rescaled
anes16$racial.resentment16 <- NA
anes16$racial.resentment16 <- as.numeric((anes16$rr116)+(anes16$rr216)+(anes16$rr316)+(anes16$rr416))/4
addmargins(table(anes16$racial.resentment16))

# evaluation of economy
anes16$econ.better16 <- NA
anes16$econ.better16 <- as.numeric(anes16$econ.better16)
anes16$econ.better16[anes16$V161141x==1] <- 1
anes16$econ.better16[anes16$V161141x==2] <- 0.75
anes16$econ.better16[anes16$V161141x==3] <- 0.5
anes16$econ.better16[anes16$V161141x==4] <- 0.25
anes16$econ.better16[anes16$V161141x==5] <- 0
addmargins(table(anes16$econ.better16))

## WHITE FEELING THERMOMETER (POST) V162314
anes16$therm.test.white16 <- NA
anes16$therm.test.white16 <- as.numeric(anes16$V162314)
table(anes16$therm.test.white16)
anes16$therm.test.white16[anes16$V162314==-9|
                            anes16$V162314==-7|
                            anes16$V162314==-6|
                            anes16$V162314==-5] <- NA
table(anes16$therm.test.white16)
anes16$therm.test.white16[anes16$V162314==0] <- 100
anes16$therm.test.white16[anes16$V162314==1] <- 99
anes16$therm.test.white16[anes16$V162314==2] <- 98
anes16$therm.test.white16[anes16$V162314==3] <- 97
anes16$therm.test.white16[anes16$V162314==4] <- 96
anes16$therm.test.white16[anes16$V162314==5] <- 95
anes16$therm.test.white16[anes16$V162314==6] <- 94
anes16$therm.test.white16[anes16$V162314==7] <- 93
anes16$therm.test.white16[anes16$V162314==8] <- 92
anes16$therm.test.white16[anes16$V162314==9] <- 91
anes16$therm.test.white16[anes16$V162314==10] <- 90
anes16$therm.test.white16[anes16$V162314==11] <- 89
anes16$therm.test.white16[anes16$V162314==12] <- 88
anes16$therm.test.white16[anes16$V162314==13] <- 87
anes16$therm.test.white16[anes16$V162314==14] <- 86
anes16$therm.test.white16[anes16$V162314==15] <- 85
anes16$therm.test.white16[anes16$V162314==16] <- 84
anes16$therm.test.white16[anes16$V162314==17] <- 83
anes16$therm.test.white16[anes16$V162314==18] <- 82
anes16$therm.test.white16[anes16$V162314==19] <- 81
anes16$therm.test.white16[anes16$V162314==20] <- 80
anes16$therm.test.white16[anes16$V162314==21] <- 79
anes16$therm.test.white16[anes16$V162314==22] <- 78
anes16$therm.test.white16[anes16$V162314==23] <- 77
anes16$therm.test.white16[anes16$V162314==24] <- 76
anes16$therm.test.white16[anes16$V162314==25] <- 75
anes16$therm.test.white16[anes16$V162314==26] <- 74
anes16$therm.test.white16[anes16$V162314==27] <- 73
anes16$therm.test.white16[anes16$V162314==28] <- 72
anes16$therm.test.white16[anes16$V162314==29] <- 71
anes16$therm.test.white16[anes16$V162314==30] <- 70
anes16$therm.test.white16[anes16$V162314==31] <- 69
anes16$therm.test.white16[anes16$V162314==32] <- 68
anes16$therm.test.white16[anes16$V162314==33] <- 67
anes16$therm.test.white16[anes16$V162314==34] <- 66
anes16$therm.test.white16[anes16$V162314==35] <- 65
anes16$therm.test.white16[anes16$V162314==36] <- 64
anes16$therm.test.white16[anes16$V162314==37] <- 63
anes16$therm.test.white16[anes16$V162314==38] <- 62
anes16$therm.test.white16[anes16$V162314==39] <- 61
anes16$therm.test.white16[anes16$V162314==40] <- 60
anes16$therm.test.white16[anes16$V162314==41] <- 59
anes16$therm.test.white16[anes16$V162314==42] <- 58
anes16$therm.test.white16[anes16$V162314==43] <- 57
anes16$therm.test.white16[anes16$V162314==44] <- 56
anes16$therm.test.white16[anes16$V162314==45] <- 55
anes16$therm.test.white16[anes16$V162314==46] <- 54
anes16$therm.test.white16[anes16$V162314==47] <- 53
anes16$therm.test.white16[anes16$V162314==48] <- 52
anes16$therm.test.white16[anes16$V162314==49] <- 51
anes16$therm.test.white16[anes16$V162314==50] <- 50
anes16$therm.test.white16[anes16$V162314==51] <- 49
anes16$therm.test.white16[anes16$V162314==52] <- 48
anes16$therm.test.white16[anes16$V162314==53] <- 47
anes16$therm.test.white16[anes16$V162314==54] <- 46
anes16$therm.test.white16[anes16$V162314==55] <- 45
anes16$therm.test.white16[anes16$V162314==56] <- 44
anes16$therm.test.white16[anes16$V162314==57] <- 43
anes16$therm.test.white16[anes16$V162314==58] <- 42
anes16$therm.test.white16[anes16$V162314==59] <- 41
anes16$therm.test.white16[anes16$V162314==60] <- 40
anes16$therm.test.white16[anes16$V162314==61] <- 39
anes16$therm.test.white16[anes16$V162314==62] <- 38
anes16$therm.test.white16[anes16$V162314==63] <- 37
anes16$therm.test.white16[anes16$V162314==64] <- 36
anes16$therm.test.white16[anes16$V162314==65] <- 35
anes16$therm.test.white16[anes16$V162314==66] <- 34
anes16$therm.test.white16[anes16$V162314==67] <- 33
anes16$therm.test.white16[anes16$V162314==68] <- 32
anes16$therm.test.white16[anes16$V162314==69] <- 31
anes16$therm.test.white16[anes16$V162314==70] <- 30
anes16$therm.test.white16[anes16$V162314==71] <- 29
anes16$therm.test.white16[anes16$V162314==72] <- 28
anes16$therm.test.white16[anes16$V162314==73] <- 27
anes16$therm.test.white16[anes16$V162314==74] <- 26
anes16$therm.test.white16[anes16$V162314==75] <- 25
anes16$therm.test.white16[anes16$V162314==76] <- 24
anes16$therm.test.white16[anes16$V162314==77] <- 23
anes16$therm.test.white16[anes16$V162314==78] <- 22
anes16$therm.test.white16[anes16$V162314==79] <- 21
anes16$therm.test.white16[anes16$V162314==80] <- 20
anes16$therm.test.white16[anes16$V162314==81] <- 19
anes16$therm.test.white16[anes16$V162314==82] <- 18
anes16$therm.test.white16[anes16$V162314==83] <- 17
anes16$therm.test.white16[anes16$V162314==84] <- 16
anes16$therm.test.white16[anes16$V162314==85] <- 15
anes16$therm.test.white16[anes16$V162314==86] <- 14
anes16$therm.test.white16[anes16$V162314==87] <- 13
anes16$therm.test.white16[anes16$V162314==88] <- 12
anes16$therm.test.white16[anes16$V162314==89] <- 11
anes16$therm.test.white16[anes16$V162314==90] <- 10
anes16$therm.test.white16[anes16$V162314==91] <- 9
anes16$therm.test.white16[anes16$V162314==92] <- 8
anes16$therm.test.white16[anes16$V162314==93] <- 7
anes16$therm.test.white16[anes16$V162314==94] <- 6
anes16$therm.test.white16[anes16$V162314==95] <- 5
anes16$therm.test.white16[anes16$V162314==96] <- 4
anes16$therm.test.white16[anes16$V162314==97] <- 3
anes16$therm.test.white16[anes16$V162314==98] <- 2
anes16$therm.test.white16[anes16$V162314==99] <- 1
anes16$therm.test.white16[anes16$V162314==100] <- 0
addmargins(table(anes16$therm.test.white16))

#white thermometer re-coded and re-scaled
anes16$therm.whites16 <- NA
anes16$therm.whites16 <- as.numeric((anes16$therm.test.white16)/100)
addmargins(table(anes16$therm.whites16))

## ASIAN AMERICAN FEELING THERMOMETER
anes16$therm.test.asian.am16 <- NA
anes16$therm.test.asian.am16 <- as.numeric(anes16$V162310)
table(anes16$therm.test.asian.am16)
anes16$therm.test.asian.am16[anes16$V162310==-9|
                               anes16$V162310==-7|
                               anes16$V162310==-6|
                               anes16$V162310==-5] <- NA
table(anes16$therm.test.asian.am16)
anes16$therm.test.asian.am16[anes16$V162310==0] <- 100
anes16$therm.test.asian.am16[anes16$V162310==1] <- 99
anes16$therm.test.asian.am16[anes16$V162310==2] <- 98
anes16$therm.test.asian.am16[anes16$V162310==3] <- 97
anes16$therm.test.asian.am16[anes16$V162310==4] <- 96
anes16$therm.test.asian.am16[anes16$V162310==5] <- 95
anes16$therm.test.asian.am16[anes16$V162310==6] <- 94
anes16$therm.test.asian.am16[anes16$V162310==7] <- 93
anes16$therm.test.asian.am16[anes16$V162310==8] <- 92
anes16$therm.test.asian.am16[anes16$V162310==9] <- 91
anes16$therm.test.asian.am16[anes16$V162310==10] <- 90
anes16$therm.test.asian.am16[anes16$V162310==11] <- 89
anes16$therm.test.asian.am16[anes16$V162310==12] <- 88
anes16$therm.test.asian.am16[anes16$V162310==13] <- 87
anes16$therm.test.asian.am16[anes16$V162310==14] <- 86
anes16$therm.test.asian.am16[anes16$V162310==15] <- 85
anes16$therm.test.asian.am16[anes16$V162310==16] <- 84
anes16$therm.test.asian.am16[anes16$V162310==17] <- 83
anes16$therm.test.asian.am16[anes16$V162310==18] <- 82
anes16$therm.test.asian.am16[anes16$V162310==19] <- 81
anes16$therm.test.asian.am16[anes16$V162310==20] <- 80
anes16$therm.test.asian.am16[anes16$V162310==21] <- 79
anes16$therm.test.asian.am16[anes16$V162310==22] <- 78
anes16$therm.test.asian.am16[anes16$V162310==23] <- 77
anes16$therm.test.asian.am16[anes16$V162310==24] <- 76
anes16$therm.test.asian.am16[anes16$V162310==25] <- 75
anes16$therm.test.asian.am16[anes16$V162310==26] <- 74
anes16$therm.test.asian.am16[anes16$V162310==27] <- 73
anes16$therm.test.asian.am16[anes16$V162310==28] <- 72
anes16$therm.test.asian.am16[anes16$V162310==29] <- 71
anes16$therm.test.asian.am16[anes16$V162310==30] <- 70
anes16$therm.test.asian.am16[anes16$V162310==31] <- 69
anes16$therm.test.asian.am16[anes16$V162310==32] <- 68
anes16$therm.test.asian.am16[anes16$V162310==33] <- 67
anes16$therm.test.asian.am16[anes16$V162310==34] <- 66
anes16$therm.test.asian.am16[anes16$V162310==35] <- 65
anes16$therm.test.asian.am16[anes16$V162310==36] <- 64
anes16$therm.test.asian.am16[anes16$V162310==37] <- 63
anes16$therm.test.asian.am16[anes16$V162310==38] <- 62
anes16$therm.test.asian.am16[anes16$V162310==39] <- 61
anes16$therm.test.asian.am16[anes16$V162310==40] <- 60
anes16$therm.test.asian.am16[anes16$V162310==41] <- 59
anes16$therm.test.asian.am16[anes16$V162310==42] <- 58
anes16$therm.test.asian.am16[anes16$V162310==43] <- 57
anes16$therm.test.asian.am16[anes16$V162310==44] <- 56
anes16$therm.test.asian.am16[anes16$V162310==45] <- 55
anes16$therm.test.asian.am16[anes16$V162310==46] <- 54
anes16$therm.test.asian.am16[anes16$V162310==47] <- 53
anes16$therm.test.asian.am16[anes16$V162310==48] <- 52
anes16$therm.test.asian.am16[anes16$V162310==49] <- 51
anes16$therm.test.asian.am16[anes16$V162310==50] <- 50
anes16$therm.test.asian.am16[anes16$V162310==51] <- 49
anes16$therm.test.asian.am16[anes16$V162310==52] <- 48
anes16$therm.test.asian.am16[anes16$V162310==53] <- 47
anes16$therm.test.asian.am16[anes16$V162310==54] <- 46
anes16$therm.test.asian.am16[anes16$V162310==55] <- 45
anes16$therm.test.asian.am16[anes16$V162310==56] <- 44
anes16$therm.test.asian.am16[anes16$V162310==57] <- 43
anes16$therm.test.asian.am16[anes16$V162310==58] <- 42
anes16$therm.test.asian.am16[anes16$V162310==59] <- 41
anes16$therm.test.asian.am16[anes16$V162310==60] <- 40
anes16$therm.test.asian.am16[anes16$V162310==61] <- 39
anes16$therm.test.asian.am16[anes16$V162310==62] <- 38
anes16$therm.test.asian.am16[anes16$V162310==63] <- 37
anes16$therm.test.asian.am16[anes16$V162310==64] <- 36
anes16$therm.test.asian.am16[anes16$V162310==65] <- 35
anes16$therm.test.asian.am16[anes16$V162310==66] <- 34
anes16$therm.test.asian.am16[anes16$V162310==67] <- 33
anes16$therm.test.asian.am16[anes16$V162310==68] <- 32
anes16$therm.test.asian.am16[anes16$V162310==69] <- 31
anes16$therm.test.asian.am16[anes16$V162310==70] <- 30
anes16$therm.test.asian.am16[anes16$V162310==71] <- 29
anes16$therm.test.asian.am16[anes16$V162310==72] <- 28
anes16$therm.test.asian.am16[anes16$V162310==73] <- 27
anes16$therm.test.asian.am16[anes16$V162310==74] <- 26
anes16$therm.test.asian.am16[anes16$V162310==75] <- 25
anes16$therm.test.asian.am16[anes16$V162310==76] <- 24
anes16$therm.test.asian.am16[anes16$V162310==77] <- 23
anes16$therm.test.asian.am16[anes16$V162310==78] <- 22
anes16$therm.test.asian.am16[anes16$V162310==79] <- 21
anes16$therm.test.asian.am16[anes16$V162310==80] <- 20
anes16$therm.test.asian.am16[anes16$V162310==81] <- 19
anes16$therm.test.asian.am16[anes16$V162310==82] <- 18
anes16$therm.test.asian.am16[anes16$V162310==83] <- 17
anes16$therm.test.asian.am16[anes16$V162310==84] <- 16
anes16$therm.test.asian.am16[anes16$V162310==85] <- 15
anes16$therm.test.asian.am16[anes16$V162310==86] <- 14
anes16$therm.test.asian.am16[anes16$V162310==87] <- 13
anes16$therm.test.asian.am16[anes16$V162310==88] <- 12
anes16$therm.test.asian.am16[anes16$V162310==89] <- 11
anes16$therm.test.asian.am16[anes16$V162310==90] <- 10
anes16$therm.test.asian.am16[anes16$V162310==91] <- 9
anes16$therm.test.asian.am16[anes16$V162310==92] <- 8
anes16$therm.test.asian.am16[anes16$V162310==93] <- 7
anes16$therm.test.asian.am16[anes16$V162310==94] <- 6
anes16$therm.test.asian.am16[anes16$V162310==95] <- 5
anes16$therm.test.asian.am16[anes16$V162310==96] <- 4
anes16$therm.test.asian.am16[anes16$V162310==97] <- 3
anes16$therm.test.asian.am16[anes16$V162310==98] <- 2
anes16$therm.test.asian.am16[anes16$V162310==99] <- 1
anes16$therm.test.asian.am16[anes16$V162310==100] <- 0
addmargins(table(anes16$therm.test.asian.am16))

#asian american feeling thermometer recoded and rescaled
anes16$therm.asian.americans16 <- NA
anes16$therm.asian.americans16 <- as.numeric((anes16$therm.test.asian.am16)/100)
addmargins(table(anes16$therm.asian.americans16))

## HISPANIC FEELING THERMOMETER
addmargins(table(anes16$V162311))
anes16$therm.test.hispanic16 <- NA
anes16$therm.test.hispanic16 <- as.numeric(anes16$V162311)
table(anes16$therm.test.hispanic16)
anes16$therm.test.hispanic16[anes16$V162311==-9|
                               anes16$V162311==-7|
                               anes16$V162311==-6|
                               anes16$V162311==-5] <- NA
table(anes16$therm.test.hispanic16)
anes16$therm.test.hispanic16[anes16$V162311==0] <- 100
anes16$therm.test.hispanic16[anes16$V162311==1] <- 99
anes16$therm.test.hispanic16[anes16$V162311==2] <- 98
anes16$therm.test.hispanic16[anes16$V162311==3] <- 97
anes16$therm.test.hispanic16[anes16$V162311==4] <- 96
anes16$therm.test.hispanic16[anes16$V162311==5] <- 95
anes16$therm.test.hispanic16[anes16$V162311==6] <- 94
anes16$therm.test.hispanic16[anes16$V162311==7] <- 93
anes16$therm.test.hispanic16[anes16$V162311==8] <- 92
anes16$therm.test.hispanic16[anes16$V162311==9] <- 91
anes16$therm.test.hispanic16[anes16$V162311==10] <- 90
anes16$therm.test.hispanic16[anes16$V162311==11] <- 89
anes16$therm.test.hispanic16[anes16$V162311==12] <- 88
anes16$therm.test.hispanic16[anes16$V162311==13] <- 87
anes16$therm.test.hispanic16[anes16$V162311==14] <- 86
anes16$therm.test.hispanic16[anes16$V162311==15] <- 85
anes16$therm.test.hispanic16[anes16$V162311==16] <- 84
anes16$therm.test.hispanic16[anes16$V162311==17] <- 83
anes16$therm.test.hispanic16[anes16$V162311==18] <- 82
anes16$therm.test.hispanic16[anes16$V162311==19] <- 81
anes16$therm.test.hispanic16[anes16$V162311==20] <- 80
anes16$therm.test.hispanic16[anes16$V162311==21] <- 79
anes16$therm.test.hispanic16[anes16$V162311==22] <- 78
anes16$therm.test.hispanic16[anes16$V162311==23] <- 77
anes16$therm.test.hispanic16[anes16$V162311==24] <- 76
anes16$therm.test.hispanic16[anes16$V162311==25] <- 75
anes16$therm.test.hispanic16[anes16$V162311==26] <- 74
anes16$therm.test.hispanic16[anes16$V162311==27] <- 73
anes16$therm.test.hispanic16[anes16$V162311==28] <- 72
anes16$therm.test.hispanic16[anes16$V162311==29] <- 71
anes16$therm.test.hispanic16[anes16$V162311==30] <- 70
anes16$therm.test.hispanic16[anes16$V162311==31] <- 69
anes16$therm.test.hispanic16[anes16$V162311==32] <- 68
anes16$therm.test.hispanic16[anes16$V162311==33] <- 67
anes16$therm.test.hispanic16[anes16$V162311==34] <- 66
anes16$therm.test.hispanic16[anes16$V162311==35] <- 65
anes16$therm.test.hispanic16[anes16$V162311==36] <- 64
anes16$therm.test.hispanic16[anes16$V162311==37] <- 63
anes16$therm.test.hispanic16[anes16$V162311==38] <- 62
anes16$therm.test.hispanic16[anes16$V162311==39] <- 61
anes16$therm.test.hispanic16[anes16$V162311==40] <- 60
anes16$therm.test.hispanic16[anes16$V162311==41] <- 59
anes16$therm.test.hispanic16[anes16$V162311==42] <- 58
anes16$therm.test.hispanic16[anes16$V162311==43] <- 57
anes16$therm.test.hispanic16[anes16$V162311==44] <- 56
anes16$therm.test.hispanic16[anes16$V162311==45] <- 55
anes16$therm.test.hispanic16[anes16$V162311==46] <- 54
anes16$therm.test.hispanic16[anes16$V162311==47] <- 53
anes16$therm.test.hispanic16[anes16$V162311==48] <- 52
anes16$therm.test.hispanic16[anes16$V162311==49] <- 51
anes16$therm.test.hispanic16[anes16$V162311==50] <- 50
anes16$therm.test.hispanic16[anes16$V162311==51] <- 49
anes16$therm.test.hispanic16[anes16$V162311==52] <- 48
anes16$therm.test.hispanic16[anes16$V162311==53] <- 47
anes16$therm.test.hispanic16[anes16$V162311==54] <- 46
anes16$therm.test.hispanic16[anes16$V162311==55] <- 45
anes16$therm.test.hispanic16[anes16$V162311==56] <- 44
anes16$therm.test.hispanic16[anes16$V162311==57] <- 43
anes16$therm.test.hispanic16[anes16$V162311==58] <- 42
anes16$therm.test.hispanic16[anes16$V162311==59] <- 41
anes16$therm.test.hispanic16[anes16$V162311==60] <- 40
anes16$therm.test.hispanic16[anes16$V162311==61] <- 39
anes16$therm.test.hispanic16[anes16$V162311==62] <- 38
anes16$therm.test.hispanic16[anes16$V162311==63] <- 37
anes16$therm.test.hispanic16[anes16$V162311==64] <- 36
anes16$therm.test.hispanic16[anes16$V162311==65] <- 35
anes16$therm.test.hispanic16[anes16$V162311==66] <- 34
anes16$therm.test.hispanic16[anes16$V162311==67] <- 33
anes16$therm.test.hispanic16[anes16$V162311==68] <- 32
anes16$therm.test.hispanic16[anes16$V162311==69] <- 31
anes16$therm.test.hispanic16[anes16$V162311==70] <- 30
anes16$therm.test.hispanic16[anes16$V162311==71] <- 29
anes16$therm.test.hispanic16[anes16$V162311==72] <- 28
anes16$therm.test.hispanic16[anes16$V162311==73] <- 27
anes16$therm.test.hispanic16[anes16$V162311==74] <- 26
anes16$therm.test.hispanic16[anes16$V162311==75] <- 25
anes16$therm.test.hispanic16[anes16$V162311==76] <- 24
anes16$therm.test.hispanic16[anes16$V162311==77] <- 23
anes16$therm.test.hispanic16[anes16$V162311==78] <- 22
anes16$therm.test.hispanic16[anes16$V162311==79] <- 21
anes16$therm.test.hispanic16[anes16$V162311==80] <- 20
anes16$therm.test.hispanic16[anes16$V162311==81] <- 19
anes16$therm.test.hispanic16[anes16$V162311==82] <- 18
anes16$therm.test.hispanic16[anes16$V162311==83] <- 17
anes16$therm.test.hispanic16[anes16$V162311==84] <- 16
anes16$therm.test.hispanic16[anes16$V162311==85] <- 15
anes16$therm.test.hispanic16[anes16$V162311==86] <- 14
anes16$therm.test.hispanic16[anes16$V162311==87] <- 13
anes16$therm.test.hispanic16[anes16$V162311==88] <- 12
anes16$therm.test.hispanic16[anes16$V162311==89] <- 11
anes16$therm.test.hispanic16[anes16$V162311==90] <- 10
anes16$therm.test.hispanic16[anes16$V162311==91] <- 9
anes16$therm.test.hispanic16[anes16$V162311==92] <- 8
anes16$therm.test.hispanic16[anes16$V162311==93] <- 7
anes16$therm.test.hispanic16[anes16$V162311==94] <- 6
anes16$therm.test.hispanic16[anes16$V162311==95] <- 5
anes16$therm.test.hispanic16[anes16$V162311==96] <- 4
anes16$therm.test.hispanic16[anes16$V162311==97] <- 3
anes16$therm.test.hispanic16[anes16$V162311==98] <- 2
anes16$therm.test.hispanic16[anes16$V162311==99] <- 1
anes16$therm.test.hispanic16[anes16$V162311==100] <- 0
addmargins(table(anes16$therm.test.hispanic16))

#hispanic feeling thermometer re-scale and re-coded
anes16$therm.hispanics16 <- NA
anes16$therm.hispanics16 <- as.numeric((anes16$therm.test.hispanic16)/100)
addmargins(table(anes16$therm.hispanics16))

#GENDER
anes16$female16 <- NA
anes16$female16 <- as.numeric(anes16$female16)
anes16$female16[anes16$V161342==1] <- 0
anes16$female16[anes16$V161342==2] <- 1
addmargins(table(anes16$female16))



#re-coded data from 2020

#partisanship
anes20$partyid20 <- NA
anes20$partyid20 <- as.numeric(anes20$partyid20)
anes20$partyid20[anes20$V201231x==1] <- 1
anes20$partyid20[anes20$V201231x==2] <- 0.833
anes20$partyid20[anes20$V201231x==3] <- 0.667
anes20$partyid20[anes20$V201231x==4] <- 0.5
anes20$partyid20[anes20$V201231x==5] <- 0.333
anes20$partyid20[anes20$V201231x==6] <- 0.167
anes20$partyid20[anes20$V201231x==7] <- 0
addmargins(table(anes20$partyid20))

#evaluation of economy
anes20$econ.better20 <- NA
anes20$econ.better20 <- as.numeric(anes20$econ.better20)
anes20$econ.better20[anes20$V201327x==1] <-1 
anes20$econ.better20[anes20$V201327x==2] <-0.75 
anes20$econ.better20[anes20$V201327x==3] <-0.5 
anes20$econ.better20[anes20$V201327x==4] <- 0.25
anes20$econ.better20[anes20$V201327x==5] <- 0
addmargins(table(anes20$econ.better20))  

#religious affiliation
anes20$protestant20 <- NA
anes20$protestant20 <- as.numeric(anes20$protestant20)
anes20$protestant20[anes20$V201435==1] <- 1
anes20$protestant20[anes20$V201435==2] <- 0
anes20$protestant20[anes20$V201435==3] <- 0
anes20$protestant20[anes20$V201435==4] <- 0
anes20$protestant20[anes20$V201435==5] <- 0
anes20$protestant20[anes20$V201435==6] <- 0
anes20$protestant20[anes20$V201435==7] <- 0
anes20$protestant20[anes20$V201435==8] <- 0
anes20$protestant20[anes20$V201435==9] <- 0
anes20$protestant20[anes20$V201435==10] <- 0
anes20$protestant20[anes20$V201435==11] <- 0
anes20$protestant20[anes20$V201435==12] <- 0
addmargins(table(anes20$protestant20))

#AGE
anes20$age.uncleaned.20 <- NA
anes20$age.uncleaned.20 <- as.numeric(anes20$V201507x)
anes20$age.uncleaned.20[anes20$V201507x==-9] <- NA
addmargins(table(anes20$age.uncleaned.20))

anes20$age20 <- NA
anes20$age20 <- as.numeric((anes20$age.uncleaned.20)/100)
addmargins(table(anes20$age20))

#EDUCATION
anes20$education20 <- NA
anes20$education20 <- as.numeric(anes20$education20)
anes20$education20[anes20$V201511x==1] <- 0
anes20$education20[anes20$V201511x==2] <- 0.25
anes20$education20[anes20$V201511x==3] <- 0.5
anes20$education20[anes20$V201511x==4] <- 0.75
anes20$education20[anes20$V201511x==5] <- 1
addmargins(table(anes20$education20))

#RACE/ETHNICITY
anes20$raceethnicity20 <- NA
anes20$raceethnicity20 <- as.character(anes20$raceethnicity20)
anes20$raceethnicity20[anes20$V201549x==1] <- "1. White"
anes20$raceethnicity20[anes20$V201549x==2] <- "2. Black"
anes20$raceethnicity20[anes20$V201549x==3] <- "5. Hispanic" 
anes20$raceethnicity20[anes20$V201549x==4] <- "3. Asian" 
anes20$raceethnicity20[anes20$V201549x==5] <- "4. Native"
anes20$raceethnicity20[anes20$V201549x==6] <- "6. Other"
addmargins(table(anes20$raceethnicity20))

anes20$white20 <- NA
anes20$white20 <- as.numeric(anes20$white20)
anes20$white20 <- ifelse(anes20$raceethnicity20=="1. White",1,0)
addmargins(table(anes20$white20))

anes20$black20 <- NA
anes20$black20 <- as.numeric(anes20$black20)
anes20$black20 <- ifelse(anes20$raceethnicity20=="2. Black",1,0)
addmargins(table(anes20$black20))

anes20$asian20 <- NA
anes20$asian20 <- as.numeric(anes20$asian20)
anes20$asian20 <- ifelse(anes20$raceethnicity20=="3. Asian",1,0)
addmargins(table(anes20$asian20))

anes20$native20 <- NA
anes20$native20 <- as.numeric(anes20$native20)
anes20$native20 <- ifelse(anes20$raceethnicity20=="4. Native",1,0)
addmargins(table(anes20$native20))

anes20$hispanic20 <- NA
anes20$hispanic20 <- as.numeric(anes20$hispanic20)
anes20$hispanic20 <- ifelse(anes20$raceethnicity20=="5. Hispanic",1,0)
addmargins(table(anes20$hispanic20))

anes20$other20 <- NA
anes20$other20 <- as.numeric(anes20$other20)
anes20$other20 <- ifelse(anes20$raceethnicity20=="6. Other",1,0)
addmargins(table(anes20$other20))

#INCOME
anes20$income20 <- NA
anes20$income20 <- as.numeric(anes20$income20)
anes20$income20[anes20$V202468x==1] <- 0
anes20$income20[anes20$V202468x==2] <- 0.0476
anes20$income20[anes20$V202468x==3] <- 0.095
anes20$income20[anes20$V202468x==4] <- 0.143
anes20$income20[anes20$V202468x==5] <- 0.1905
anes20$income20[anes20$V202468x==6] <- 0.238
anes20$income20[anes20$V202468x==7] <- 0.286
anes20$income20[anes20$V202468x==8] <- 0.333
anes20$income20[anes20$V202468x==9] <- 0.381
anes20$income20[anes20$V202468x==10] <- 0.426
anes20$income20[anes20$V202468x==11] <- 0.476
anes20$income20[anes20$V202468x==12] <- 0.524
anes20$income20[anes20$V202468x==13] <- 0.571
anes20$income20[anes20$V202468x==14] <- 0.619
anes20$income20[anes20$V202468x==15] <- 0.667
anes20$income20[anes20$V202468x==16] <- 0.714
anes20$income20[anes20$V202468x==17] <- 0.762
anes20$income20[anes20$V202468x==18] <- 0.8095
anes20$income20[anes20$V202468x==19] <- 0.857
anes20$income20[anes20$V202468x==20] <- 0.905
anes20$income20[anes20$V202468x==21] <- 0.952
anes20$income20[anes20$V202468x==22] <- 1
addmargins(table(anes20$income20))

#VOTE CHOICE IN 2020 (Trump)
anes20$trump.general20 <- NA
anes20$trump.general20 <- as.numeric(anes20$trump.general20)
anes20$trump.general20[anes20$V202110x==1] <-0 
anes20$trump.general20[anes20$V202110x==2] <-1 
anes20$trump.general20[anes20$V202110x==3] <-0 
anes20$trump.general20[anes20$V202110x==4] <-0 
anes20$trump.general20[anes20$V202110x==5] <-0 
addmargins(table(anes20$trump.general20))  

#black racial resentment 1
anes20$rr220 <- NA
anes20$rr220 <- as.numeric(anes20$rr220)
anes20$rr220[anes20$V202300==1] <- 1
anes20$rr220[anes20$V202300==2] <- 0.75
anes20$rr220[anes20$V202300==3] <- 0.5
anes20$rr220[anes20$V202300==4] <- 0.25
anes20$rr220[anes20$V202300==5] <- 0
addmargins(table(anes20$rr220))

#racial resentment 2
anes20$rr120 <- NA
anes20$rr120 <- as.numeric(anes20$rr120)
anes20$rr120[anes20$V202301==1] <- 0
anes20$rr120[anes20$V202301==2] <- 0.25
anes20$rr120[anes20$V202301==3] <- 0.5
anes20$rr120[anes20$V202301==4] <- 0.75
anes20$rr120[anes20$V202301==5] <- 1
addmargins(table(anes20$rr120))

#racial resentment 3
anes20$rr320 <- NA
anes20$rr320 <- as.numeric(anes20$rr320)
anes20$rr320[anes20$V202302==1] <- 0
anes20$rr320[anes20$V202302==2] <- 0.25
anes20$rr320[anes20$V202302==3] <- 0.5
anes20$rr320[anes20$V202302==4] <- 0.75
anes20$rr320[anes20$V202302==5] <- 1
addmargins(table(anes20$rr320))

#racial resentment 4
anes20$rr420 <- NA
anes20$rr420 <- as.numeric(anes20$rr420)
anes20$rr420[anes20$V202303==1] <- 1
anes20$rr420[anes20$V202303==2] <- 0.75
anes20$rr420[anes20$V202303==3] <- 0.5
anes20$rr420[anes20$V202303==4] <- 0.25
anes20$rr420[anes20$V202303==5] <- 0
addmargins(table(anes20$rr420))

#racial resentment recoded and rescaled
anes20$racial.resentment20 <- NA
anes20$racial.resentment20 <- as.numeric(anes20$racial.resentment20)
anes20$racial.resentment20 <- ((anes20$rr120)+(anes20$rr220)+(anes20$rr320)+(anes20$rr420))/4
addmargins(table(anes20$racial.resentment20))

#asian american feeling thermometer recoded
anes20$therm.test.asian.am20 <- NA
anes20$therm.test.asian.am20 <- as.numeric(anes20$V202477)
table(anes20$therm.test.asian.am20)
anes20$therm.test.asian.am20[anes20$V202477==-9|
                               anes20$V202477==-7|
                               anes20$V202477==-6|
                               anes20$V202477==-5|
                               anes20$V202477==-1] <- NA
table(anes20$therm.test.asian.am20)
anes20$therm.test.asian.am20[anes20$V202477==0] <- 100
anes20$therm.test.asian.am20[anes20$V202477==1] <- 99
anes20$therm.test.asian.am20[anes20$V202477==2] <- 98
anes20$therm.test.asian.am20[anes20$V202477==3] <- 97
anes20$therm.test.asian.am20[anes20$V202477==4] <- 96
anes20$therm.test.asian.am20[anes20$V202477==5] <- 95
anes20$therm.test.asian.am20[anes20$V202477==6] <- 94
anes20$therm.test.asian.am20[anes20$V202477==7] <- 93
anes20$therm.test.asian.am20[anes20$V202477==8] <- 92
anes20$therm.test.asian.am20[anes20$V202477==9] <- 91
anes20$therm.test.asian.am20[anes20$V202477==10] <- 90
anes20$therm.test.asian.am20[anes20$V202477==11] <- 89
anes20$therm.test.asian.am20[anes20$V202477==12] <- 88
anes20$therm.test.asian.am20[anes20$V202477==13] <- 87
anes20$therm.test.asian.am20[anes20$V202477==14] <- 86
anes20$therm.test.asian.am20[anes20$V202477==15] <- 85
anes20$therm.test.asian.am20[anes20$V202477==16] <- 84
anes20$therm.test.asian.am20[anes20$V202477==17] <- 83
anes20$therm.test.asian.am20[anes20$V202477==18] <- 82
anes20$therm.test.asian.am20[anes20$V202477==19] <- 81
anes20$therm.test.asian.am20[anes20$V202477==20] <- 80
anes20$therm.test.asian.am20[anes20$V202477==21] <- 79
anes20$therm.test.asian.am20[anes20$V202477==22] <- 78
anes20$therm.test.asian.am20[anes20$V202477==23] <- 77
anes20$therm.test.asian.am20[anes20$V202477==24] <- 76
anes20$therm.test.asian.am20[anes20$V202477==25] <- 75
anes20$therm.test.asian.am20[anes20$V202477==26] <- 74
anes20$therm.test.asian.am20[anes20$V202477==27] <- 73
anes20$therm.test.asian.am20[anes20$V202477==28] <- 72
anes20$therm.test.asian.am20[anes20$V202477==29] <- 71
anes20$therm.test.asian.am20[anes20$V202477==30] <- 70
anes20$therm.test.asian.am20[anes20$V202477==31] <- 69
anes20$therm.test.asian.am20[anes20$V202477==32] <- 68
anes20$therm.test.asian.am20[anes20$V202477==33] <- 67
anes20$therm.test.asian.am20[anes20$V202477==34] <- 66
anes20$therm.test.asian.am20[anes20$V202477==35] <- 65
anes20$therm.test.asian.am20[anes20$V202477==36] <- 64
anes20$therm.test.asian.am20[anes20$V202477==37] <- 63
anes20$therm.test.asian.am20[anes20$V202477==38] <- 62
anes20$therm.test.asian.am20[anes20$V202477==39] <- 61
anes20$therm.test.asian.am20[anes20$V202477==40] <- 60
anes20$therm.test.asian.am20[anes20$V202477==41] <- 59
anes20$therm.test.asian.am20[anes20$V202477==42] <- 58
anes20$therm.test.asian.am20[anes20$V202477==43] <- 57
anes20$therm.test.asian.am20[anes20$V202477==44] <- 56
anes20$therm.test.asian.am20[anes20$V202477==45] <- 55
anes20$therm.test.asian.am20[anes20$V202477==46] <- 54
anes20$therm.test.asian.am20[anes20$V202477==47] <- 53
anes20$therm.test.asian.am20[anes20$V202477==48] <- 52
anes20$therm.test.asian.am20[anes20$V202477==49] <- 51
anes20$therm.test.asian.am20[anes20$V202477==50] <- 50
anes20$therm.test.asian.am20[anes20$V202477==51] <- 49
anes20$therm.test.asian.am20[anes20$V202477==52] <- 48
anes20$therm.test.asian.am20[anes20$V202477==53] <- 47
anes20$therm.test.asian.am20[anes20$V202477==54] <- 46
anes20$therm.test.asian.am20[anes20$V202477==55] <- 45
anes20$therm.test.asian.am20[anes20$V202477==56] <- 44
anes20$therm.test.asian.am20[anes20$V202477==57] <- 43
anes20$therm.test.asian.am20[anes20$V202477==58] <- 42
anes20$therm.test.asian.am20[anes20$V202477==59] <- 41
anes20$therm.test.asian.am20[anes20$V202477==60] <- 40
anes20$therm.test.asian.am20[anes20$V202477==61] <- 39
anes20$therm.test.asian.am20[anes20$V202477==62] <- 38
anes20$therm.test.asian.am20[anes20$V202477==63] <- 37
anes20$therm.test.asian.am20[anes20$V202477==64] <- 36
anes20$therm.test.asian.am20[anes20$V202477==65] <- 35
anes20$therm.test.asian.am20[anes20$V202477==66] <- 34
anes20$therm.test.asian.am20[anes20$V202477==67] <- 33
anes20$therm.test.asian.am20[anes20$V202477==68] <- 32
anes20$therm.test.asian.am20[anes20$V202477==69] <- 31
anes20$therm.test.asian.am20[anes20$V202477==70] <- 30
anes20$therm.test.asian.am20[anes20$V202477==71] <- 29
anes20$therm.test.asian.am20[anes20$V202477==72] <- 28
anes20$therm.test.asian.am20[anes20$V202477==73] <- 27
anes20$therm.test.asian.am20[anes20$V202477==74] <- 26
anes20$therm.test.asian.am20[anes20$V202477==75] <- 25
anes20$therm.test.asian.am20[anes20$V202477==76] <- 24
anes20$therm.test.asian.am20[anes20$V202477==77] <- 23
anes20$therm.test.asian.am20[anes20$V202477==78] <- 22
anes20$therm.test.asian.am20[anes20$V202477==79] <- 21
anes20$therm.test.asian.am20[anes20$V202477==80] <- 20
anes20$therm.test.asian.am20[anes20$V202477==81] <- 19
anes20$therm.test.asian.am20[anes20$V202477==82] <- 18
anes20$therm.test.asian.am20[anes20$V202477==83] <- 17
anes20$therm.test.asian.am20[anes20$V202477==84] <- 16
anes20$therm.test.asian.am20[anes20$V202477==85] <- 15
anes20$therm.test.asian.am20[anes20$V202477==86] <- 14
anes20$therm.test.asian.am20[anes20$V202477==87] <- 13
anes20$therm.test.asian.am20[anes20$V202477==88] <- 12
anes20$therm.test.asian.am20[anes20$V202477==89] <- 11
anes20$therm.test.asian.am20[anes20$V202477==90] <- 10
anes20$therm.test.asian.am20[anes20$V202477==91] <- 9
anes20$therm.test.asian.am20[anes20$V202477==92] <- 8
anes20$therm.test.asian.am20[anes20$V202477==93] <- 7
anes20$therm.test.asian.am20[anes20$V202477==94] <- 6
anes20$therm.test.asian.am20[anes20$V202477==95] <- 5
anes20$therm.test.asian.am20[anes20$V202477==96] <- 4
anes20$therm.test.asian.am20[anes20$V202477==97] <- 3
anes20$therm.test.asian.am20[anes20$V202477==98] <- 2
anes20$therm.test.asian.am20[anes20$V202477==99] <- 1
anes20$therm.test.asian.am20[anes20$V202477==100] <- 0
addmargins(table(anes20$therm.test.asian.am20))

#asian american feeling thermometer recoded and rescaled
anes20$therm.asian.americans20 <- NA
anes20$therm.asian.americans20 <- as.numeric((anes20$therm.test.asian.am20)/100)
addmargins(table(anes20$therm.asian.americans20))

#HISPANICS FEELING THERMOMETER
anes20$therm.test.hispanic20 <- NA
anes20$therm.test.hispanic20 <- as.numeric(anes20$V202479)
table(anes20$therm.test.hispanic20)
anes20$therm.test.hispanic20[anes20$V202479==-9|
                               anes20$V202479==-7|
                               anes20$V202479==-6|
                               anes20$V202479==-5] <- NA
table(anes20$therm.test.hispanic20)
anes20$therm.test.hispanic20[anes20$V202479==0] <- 100
anes20$therm.test.hispanic20[anes20$V202479==1] <- 99
anes20$therm.test.hispanic20[anes20$V202479==2] <- 98
anes20$therm.test.hispanic20[anes20$V202479==3] <- 97
anes20$therm.test.hispanic20[anes20$V202479==4] <- 96
anes20$therm.test.hispanic20[anes20$V202479==5] <- 95
anes20$therm.test.hispanic20[anes20$V202479==6] <- 94
anes20$therm.test.hispanic20[anes20$V202479==7] <- 93
anes20$therm.test.hispanic20[anes20$V202479==8] <- 92
anes20$therm.test.hispanic20[anes20$V202479==9] <- 91
anes20$therm.test.hispanic20[anes20$V202479==10] <- 90
anes20$therm.test.hispanic20[anes20$V202479==11] <- 89
anes20$therm.test.hispanic20[anes20$V202479==12] <- 88
anes20$therm.test.hispanic20[anes20$V202479==13] <- 87
anes20$therm.test.hispanic20[anes20$V202479==14] <- 86
anes20$therm.test.hispanic20[anes20$V202479==15] <- 85
anes20$therm.test.hispanic20[anes20$V202479==16] <- 84
anes20$therm.test.hispanic20[anes20$V202479==17] <- 83
anes20$therm.test.hispanic20[anes20$V202479==18] <- 82
anes20$therm.test.hispanic20[anes20$V202479==19] <- 81
anes20$therm.test.hispanic20[anes20$V202479==20] <- 80
anes20$therm.test.hispanic20[anes20$V202479==21] <- 79
anes20$therm.test.hispanic20[anes20$V202479==22] <- 78
anes20$therm.test.hispanic20[anes20$V202479==23] <- 77
anes20$therm.test.hispanic20[anes20$V202479==24] <- 76
anes20$therm.test.hispanic20[anes20$V202479==25] <- 75
anes20$therm.test.hispanic20[anes20$V202479==26] <- 74
anes20$therm.test.hispanic20[anes20$V202479==27] <- 73
anes20$therm.test.hispanic20[anes20$V202479==28] <- 72
anes20$therm.test.hispanic20[anes20$V202479==29] <- 71
anes20$therm.test.hispanic20[anes20$V202479==30] <- 70
anes20$therm.test.hispanic20[anes20$V202479==31] <- 69
anes20$therm.test.hispanic20[anes20$V202479==32] <- 68
anes20$therm.test.hispanic20[anes20$V202479==33] <- 67
anes20$therm.test.hispanic20[anes20$V202479==34] <- 66
anes20$therm.test.hispanic20[anes20$V202479==35] <- 65
anes20$therm.test.hispanic20[anes20$V202479==36] <- 64
anes20$therm.test.hispanic20[anes20$V202479==37] <- 63
anes20$therm.test.hispanic20[anes20$V202479==38] <- 62
anes20$therm.test.hispanic20[anes20$V202479==39] <- 61
anes20$therm.test.hispanic20[anes20$V202479==40] <- 60
anes20$therm.test.hispanic20[anes20$V202479==41] <- 59
anes20$therm.test.hispanic20[anes20$V202479==42] <- 58
anes20$therm.test.hispanic20[anes20$V202479==43] <- 57
anes20$therm.test.hispanic20[anes20$V202479==44] <- 56
anes20$therm.test.hispanic20[anes20$V202479==45] <- 55
anes20$therm.test.hispanic20[anes20$V202479==46] <- 54
anes20$therm.test.hispanic20[anes20$V202479==47] <- 53
anes20$therm.test.hispanic20[anes20$V202479==48] <- 52
anes20$therm.test.hispanic20[anes20$V202479==49] <- 51
anes20$therm.test.hispanic20[anes20$V202479==50] <- 50
anes20$therm.test.hispanic20[anes20$V202479==51] <- 49
anes20$therm.test.hispanic20[anes20$V202479==52] <- 48
anes20$therm.test.hispanic20[anes20$V202479==53] <- 47
anes20$therm.test.hispanic20[anes20$V202479==54] <- 46
anes20$therm.test.hispanic20[anes20$V202479==55] <- 45
anes20$therm.test.hispanic20[anes20$V202479==56] <- 44
anes20$therm.test.hispanic20[anes20$V202479==57] <- 43
anes20$therm.test.hispanic20[anes20$V202479==58] <- 42
anes20$therm.test.hispanic20[anes20$V202479==59] <- 41
anes20$therm.test.hispanic20[anes20$V202479==60] <- 40
anes20$therm.test.hispanic20[anes20$V202479==61] <- 39
anes20$therm.test.hispanic20[anes20$V202479==62] <- 38
anes20$therm.test.hispanic20[anes20$V202479==63] <- 37
anes20$therm.test.hispanic20[anes20$V202479==64] <- 36
anes20$therm.test.hispanic20[anes20$V202479==65] <- 35
anes20$therm.test.hispanic20[anes20$V202479==66] <- 34
anes20$therm.test.hispanic20[anes20$V202479==67] <- 33
anes20$therm.test.hispanic20[anes20$V202479==68] <- 32
anes20$therm.test.hispanic20[anes20$V202479==69] <- 31
anes20$therm.test.hispanic20[anes20$V202479==70] <- 30
anes20$therm.test.hispanic20[anes20$V202479==71] <- 29
anes20$therm.test.hispanic20[anes20$V202479==72] <- 28
anes20$therm.test.hispanic20[anes20$V202479==73] <- 27
anes20$therm.test.hispanic20[anes20$V202479==74] <- 26
anes20$therm.test.hispanic20[anes20$V202479==75] <- 25
anes20$therm.test.hispanic20[anes20$V202479==76] <- 24
anes20$therm.test.hispanic20[anes20$V202479==77] <- 23
anes20$therm.test.hispanic20[anes20$V202479==78] <- 22
anes20$therm.test.hispanic20[anes20$V202479==79] <- 21
anes20$therm.test.hispanic20[anes20$V202479==80] <- 20
anes20$therm.test.hispanic20[anes20$V202479==81] <- 19
anes20$therm.test.hispanic20[anes20$V202479==82] <- 18
anes20$therm.test.hispanic20[anes20$V202479==83] <- 17
anes20$therm.test.hispanic20[anes20$V202479==84] <- 16
anes20$therm.test.hispanic20[anes20$V202479==85] <- 15
anes20$therm.test.hispanic20[anes20$V202479==86] <- 14
anes20$therm.test.hispanic20[anes20$V202479==87] <- 13
anes20$therm.test.hispanic20[anes20$V202479==88] <- 12
anes20$therm.test.hispanic20[anes20$V202479==89] <- 11
anes20$therm.test.hispanic20[anes20$V202479==90] <- 10
anes20$therm.test.hispanic20[anes20$V202479==91] <- 9
anes20$therm.test.hispanic20[anes20$V202479==92] <- 8
anes20$therm.test.hispanic20[anes20$V202479==93] <- 7
anes20$therm.test.hispanic20[anes20$V202479==94] <- 6
anes20$therm.test.hispanic20[anes20$V202479==95] <- 5
anes20$therm.test.hispanic20[anes20$V202479==96] <- 4
anes20$therm.test.hispanic20[anes20$V202479==97] <- 3
anes20$therm.test.hispanic20[anes20$V202479==98] <- 2
anes20$therm.test.hispanic20[anes20$V202479==99] <- 1
anes20$therm.test.hispanic20[anes20$V202479==100] <- 0
addmargins(table(anes20$therm.test.hispanic20))

#hispanic feeling thermometer re-coded and re-scaled
anes20$therm.hispanics20 <- NA
anes20$therm.hispanics20 <- as.numeric((anes20$therm.test.hispanic20)/100)
addmargins(table(anes20$therm.hispanics20))

#WHITES FEELING THERMOMETER
anes20$therm.test.white20 <- NA
anes20$therm.test.white20 <- as.numeric(anes20$V202482)
table(anes20$therm.test.white20)
anes20$therm.test.white20[anes20$V202482==-9|
                            anes20$V202482==-7|
                            anes20$V202482==-6|
                            anes20$V202482==-5] <- NA
table(anes20$therm.test.white20)
anes20$therm.test.white20[anes20$V202482==0] <- 100
anes20$therm.test.white20[anes20$V202482==1] <- 99
anes20$therm.test.white20[anes20$V202482==2] <- 98
anes20$therm.test.white20[anes20$V202482==3] <- 97
anes20$therm.test.white20[anes20$V202482==4] <- 96
anes20$therm.test.white20[anes20$V202482==5] <- 95
anes20$therm.test.white20[anes20$V202482==6] <- 94
anes20$therm.test.white20[anes20$V202482==7] <- 93
anes20$therm.test.white20[anes20$V202482==8] <- 92
anes20$therm.test.white20[anes20$V202482==9] <- 91
anes20$therm.test.white20[anes20$V202482==10] <- 90
anes20$therm.test.white20[anes20$V202482==11] <- 89
anes20$therm.test.white20[anes20$V202482==12] <- 88
anes20$therm.test.white20[anes20$V202482==13] <- 87
anes20$therm.test.white20[anes20$V202482==14] <- 86
anes20$therm.test.white20[anes20$V202482==15] <- 85
anes20$therm.test.white20[anes20$V202482==16] <- 84
anes20$therm.test.white20[anes20$V202482==17] <- 83
anes20$therm.test.white20[anes20$V202482==18] <- 82
anes20$therm.test.white20[anes20$V202482==19] <- 81
anes20$therm.test.white20[anes20$V202482==20] <- 80
anes20$therm.test.white20[anes20$V202482==21] <- 79
anes20$therm.test.white20[anes20$V202482==22] <- 78
anes20$therm.test.white20[anes20$V202482==23] <- 77
anes20$therm.test.white20[anes20$V202482==24] <- 76
anes20$therm.test.white20[anes20$V202482==25] <- 75
anes20$therm.test.white20[anes20$V202482==26] <- 74
anes20$therm.test.white20[anes20$V202482==27] <- 73
anes20$therm.test.white20[anes20$V202482==28] <- 72
anes20$therm.test.white20[anes20$V202482==29] <- 71
anes20$therm.test.white20[anes20$V202482==30] <- 70
anes20$therm.test.white20[anes20$V202482==31] <- 69
anes20$therm.test.white20[anes20$V202482==32] <- 68
anes20$therm.test.white20[anes20$V202482==33] <- 67
anes20$therm.test.white20[anes20$V202482==34] <- 66
anes20$therm.test.white20[anes20$V202482==35] <- 65
anes20$therm.test.white20[anes20$V202482==36] <- 64
anes20$therm.test.white20[anes20$V202482==37] <- 63
anes20$therm.test.white20[anes20$V202482==38] <- 62
anes20$therm.test.white20[anes20$V202482==39] <- 61
anes20$therm.test.white20[anes20$V202482==40] <- 60
anes20$therm.test.white20[anes20$V202482==41] <- 59
anes20$therm.test.white20[anes20$V202482==42] <- 58
anes20$therm.test.white20[anes20$V202482==43] <- 57
anes20$therm.test.white20[anes20$V202482==44] <- 56
anes20$therm.test.white20[anes20$V202482==45] <- 55
anes20$therm.test.white20[anes20$V202482==46] <- 54
anes20$therm.test.white20[anes20$V202482==47] <- 53
anes20$therm.test.white20[anes20$V202482==48] <- 52
anes20$therm.test.white20[anes20$V202482==49] <- 51
anes20$therm.test.white20[anes20$V202482==50] <- 50
anes20$therm.test.white20[anes20$V202482==51] <- 49
anes20$therm.test.white20[anes20$V202482==52] <- 48
anes20$therm.test.white20[anes20$V202482==53] <- 47
anes20$therm.test.white20[anes20$V202482==54] <- 46
anes20$therm.test.white20[anes20$V202482==55] <- 45
anes20$therm.test.white20[anes20$V202482==56] <- 44
anes20$therm.test.white20[anes20$V202482==57] <- 43
anes20$therm.test.white20[anes20$V202482==58] <- 42
anes20$therm.test.white20[anes20$V202482==59] <- 41
anes20$therm.test.white20[anes20$V202482==60] <- 40
anes20$therm.test.white20[anes20$V202482==61] <- 39
anes20$therm.test.white20[anes20$V202482==62] <- 38
anes20$therm.test.white20[anes20$V202482==63] <- 37
anes20$therm.test.white20[anes20$V202482==64] <- 36
anes20$therm.test.white20[anes20$V202482==65] <- 35
anes20$therm.test.white20[anes20$V202482==66] <- 34
anes20$therm.test.white20[anes20$V202482==67] <- 33
anes20$therm.test.white20[anes20$V202482==68] <- 32
anes20$therm.test.white20[anes20$V202482==69] <- 31
anes20$therm.test.white20[anes20$V202482==70] <- 30
anes20$therm.test.white20[anes20$V202482==71] <- 29
anes20$therm.test.white20[anes20$V202482==72] <- 28
anes20$therm.test.white20[anes20$V202482==73] <- 27
anes20$therm.test.white20[anes20$V202482==74] <- 26
anes20$therm.test.white20[anes20$V202482==75] <- 25
anes20$therm.test.white20[anes20$V202482==76] <- 24
anes20$therm.test.white20[anes20$V202482==77] <- 23
anes20$therm.test.white20[anes20$V202482==78] <- 22
anes20$therm.test.white20[anes20$V202482==79] <- 21
anes20$therm.test.white20[anes20$V202482==80] <- 20
anes20$therm.test.white20[anes20$V202482==81] <- 19
anes20$therm.test.white20[anes20$V202482==82] <- 18
anes20$therm.test.white20[anes20$V202482==83] <- 17
anes20$therm.test.white20[anes20$V202482==84] <- 16
anes20$therm.test.white20[anes20$V202482==85] <- 15
anes20$therm.test.white20[anes20$V202482==86] <- 14
anes20$therm.test.white20[anes20$V202482==87] <- 13
anes20$therm.test.white20[anes20$V202482==88] <- 12
anes20$therm.test.white20[anes20$V202482==89] <- 11
anes20$therm.test.white20[anes20$V202482==90] <- 10
anes20$therm.test.white20[anes20$V202482==91] <- 9
anes20$therm.test.white20[anes20$V202482==92] <- 8
anes20$therm.test.white20[anes20$V202482==93] <- 7
anes20$therm.test.white20[anes20$V202482==94] <- 6
anes20$therm.test.white20[anes20$V202482==95] <- 5
anes20$therm.test.white20[anes20$V202482==96] <- 4
anes20$therm.test.white20[anes20$V202482==97] <- 3
anes20$therm.test.white20[anes20$V202482==98] <- 2
anes20$therm.test.white20[anes20$V202482==99] <- 1
anes20$therm.test.white20[anes20$V202482==100] <- 0
addmargins(table(anes20$therm.test.white20))

#white feeling thermometer re-coded and re-scaled
anes20$therm.whites20 <- NA
anes20$therm.whites20 <- as.numeric((anes20$therm.test.white20)/100)
addmargins(table(anes20$therm.whites20))

#GENDER
anes20$female20 <- NA
anes20$female20 <- as.numeric(anes20$female20)
anes20$female20[anes20$V201600==1] <- 0
anes20$female20[anes20$V201600==2] <- 1
addmargins(table(anes20$female20))

#president's handling of covid
anes20$covidapprove <- NA
anes20$covidapprove <- as.numeric(anes20$covidapprove)
anes20$covidapprove[anes20$V201144x==1] <- 1
anes20$covidapprove[anes20$V201144x==2] <- 0.667
anes20$covidapprove[anes20$V201144x==3] <- 0.333
anes20$covidapprove[anes20$V201144x==4] <- 0
anes20$covidapprove[anes20$V201144x==-2] <- NA
addmargins(table(anes20$covidapprove))

#whether someone in household tested positive for covid
anes20$covidtest <- NA
anes20$covidtest <- as.numeric(anes20$covidtest)
anes20$covidtest[anes20$V201624==1] <- 1
anes20$covidtest[anes20$V201624==2] <- 0
anes20$covidtest[anes20$V201624==-5] <- NA
anes20$covidtest[anes20$V201624==-9] <- NA
table(anes20$covidtest)




####PANEL ANALYSIS

#rename variable in 2016 for case ID
anes16$caseid <- NA
anes16$caseid <- as.numeric(anes16$caseid)
anes16$caseid <- as.numeric(anes16$V160001_orig)

#rename variable in 2020 for case ID
anes20$caseid <- NA
anes20$caseid <- as.numeric(anes20$caseid)
anes20$caseid <- as.numeric(anes20$V160001_orig)

#look at case ID for 2016 and 2020
head(anes16$V160001_orig)
head(anes16$caseid)
head(anes20$V160001_orig)
head(anes20$caseid)

#subset only the re-interviewees from 2020 that were interviewed in 2016 too
anes20.repeats <- subset(anes20, subset=(V200003==2)) #n=2839
paneled <- merge(anes16, anes20.repeats, by="caseid") #same number of respondents, n=2839

#create vote change dependent variable
paneled$change.trump20202016 <- NA
paneled$change.trump20202016 <- as.numeric(paneled$change.trump20202016)
paneled$change.trump20202016 <- (paneled$trump.general20)-(paneled$trump.general16)
addmargins(table(paneled$change.trump20202016))
addmargins(prop.table(table(paneled$change.trump20202016)))





##REGRESSION RESULTS (Figure 1, 2, and 3; Appendix Table A)
#2008
mod1a <- glm(mccain.general08~therm.asian.americans08+
               therm.whites08+therm.hispanics08+
               racial.resentment08+
               black08+asian08+native08+hispanic08+other08+
               partyid08+econ.better08+
               age08+female08+education08+income08+protestant08,
             family='binomial', data=anes08,
             weights=anes08$V080102)
summary(mod1a)

#2012
mod2a <- glm(romney.general12~therm.asian.americans12+
               therm.whites12+therm.hispanics12+
               racial.resentment12+
               black12+asian12+native12+hispanic12+other12+
               partyid12+econ.better12+
               age12+female12+education12+income12+protestant12,
             family='binomial', data=anes12,
             weights=anes12$weight_full)
summary(mod2a)

#predictions for 2012
setup <- with(anes12,
              data.frame(therm.asian.americans12=c(0, 0.25, 0.5, 0.75, 1),
                         therm.whites12=mean(therm.whites12, na.rm=TRUE),
                         therm.hispanics12=mean(therm.hispanics12, na.rm=TRUE),
                         racial.resentment12=mean(racial.resentment12, na.rm=TRUE),
                         black12=mean(black12, na.rm=TRUE),
                         asian12=mean(asian12, na.rm=TRUE),
                         native12=mean(native12, na.rm=TRUE),
                         hispanic12=mean(hispanic12, na.rm=TRUE),
                         other12=mean(other12, na.rm=TRUE),
                         partyid12=mean(partyid12,na.rm=TRUE),
                         econ.better12=mean(econ.better12, na.rm=TRUE),
                         age12=mean(age12,na.rm=TRUE),
                         female12=mean(female12, na.rm=TRUE),
                         education12=mean(education12, na.rm=TRUE),
                         income12=mean(income12, na.rm=TRUE),
                         protestant12=mean(protestant12, na.rm=TRUE)))

setup 

preds <- predict(mod2a, setup, type="response",
                 se.fit=TRUE)

preds

predf <- preds$fit

predf 

lower <- preds$fit-(1.96*preds$se.fit)

lower 

upper <- preds$fit+(1.96*preds$se.fit)

upper

#2016
mod3a <- glm(trump.general16~therm.asian.americans16+
               therm.whites16+therm.hispanics16+
               racial.resentment16+
               black16+asian16+native16+hispanic16+other16+
               partyid16+econ.better16+
               age16+female16+education16+income16+protestant16,
             data=anes16,family='binomial',
             weights=anes16$V160102)
summary(mod3a)

#2016 predicted probabilities
setup <- with(paneled,
              data.frame(therm.asian.americans16=c(0, 0.25, 0.5, 0.75, 1),
                         therm.whites16=mean(therm.whites16, na.rm=TRUE),
                         therm.hispanics16=mean(therm.hispanics16, na.rm=TRUE),
                         racial.resentment16=mean(racial.resentment16, na.rm=TRUE),
                         black16=mean(black16, na.rm=TRUE),
                         asian16=mean(asian16, na.rm=TRUE),
                         native16=mean(native16, na.rm=TRUE),
                         hispanic16=mean(hispanic16, na.rm=TRUE),
                         other16=mean(other16, na.rm=TRUE),
                         partyid16=mean(partyid16,na.rm=TRUE),
                         econ.better16=mean(econ.better16, na.rm=TRUE),
                         age16=mean(age16,na.rm=TRUE),
                         female16=mean(female16, na.rm=TRUE),
                         education16=mean(education16, na.rm=TRUE),
                         income16=mean(income16, na.rm=TRUE),
                         protestant16=mean(protestant16, na.rm=TRUE)))

setup 

preds <- predict(mod3a, setup, type="response",
                 se.fit=TRUE)

preds

predf <- preds$fit

predf 

lower <- preds$fit-(1.96*preds$se.fit)

lower 

upper <- preds$fit+(1.96*preds$se.fit)

upper


#2020
mod4a <- glm(trump.general20~therm.asian.americans20+
               therm.whites20+therm.hispanics20+
               racial.resentment20+
               black20+asian20+native20+hispanic20+other20+
               partyid20+econ.better20+
               age20+female20+education20+income20+protestant20,
             data=anes20,family='binomial',
             weights=anes20$V200010b)
summary(mod4a)

#2020 predicted probabilities
setup <- with(anes20,
              data.frame(therm.asian.americans20=c(0, 0.25, 0.5, 0.75, 1),
                         therm.whites20=mean(therm.whites20, na.rm=TRUE),
                         therm.hispanics20=mean(therm.hispanics20, na.rm=TRUE),
                         racial.resentment20=mean(racial.resentment20, na.rm=TRUE),
                         black20=mean(black20, na.rm=TRUE),
                         asian20=mean(asian20, na.rm=TRUE),
                         native20=mean(native20, na.rm=TRUE),
                         hispanic20=mean(hispanic20, na.rm=TRUE),
                         other20=mean(other20, na.rm=TRUE),
                         partyid20=mean(partyid20,na.rm=TRUE),
                         econ.better20=mean(econ.better20, na.rm=TRUE),
                         age20=mean(age20,na.rm=TRUE),
                         female20=mean(female20, na.rm=TRUE),
                         education20=mean(education20, na.rm=TRUE),
                         income20=mean(income20, na.rm=TRUE),
                         protestant20=mean(protestant20, na.rm=TRUE)))

setup

preds <- predict(mod4a, setup, type="response",
                 se.fit=TRUE)

preds

predf <- preds$fit

predf

lower <- preds$fit-(1.96*preds$se.fit)

lower

upper <- preds$fit+(1.96*preds$se.fit)

upper



##APPENDIX TABLE B
#include controls for COVID-19 evaluations and experiences in 2020 model
mod4b <- glm(trump.general20~therm.asian.americans20+
               therm.whites20+therm.hispanics20+
               racial.resentment20+
               black20+asian20+native20+hispanic20+other20+
               partyid20+econ.better20+
               age20+female20+education20+income20+protestant20+
               covidapprove+covidtest,
             data=anes20,family='binomial',
             weights=anes20$V200010b)
summary(mod4b)


##APPENDIX TABLE C
#condition by area (report just rural area versus city) in 2020 model
anes20.area.rural <- subset(anes20, subset=(V202355==1))
anes20.area.city <- subset(anes20, subset=(V202355==4))

mod4c <- glm(trump.general20~therm.asian.americans20+
               therm.whites20+therm.hispanics20+
               racial.resentment20+
               black20+asian20+native20+hispanic20+other20+
               partyid20+econ.better20+
               age20+female20+education20+income20+protestant20,
             data=anes20.area.rural,family='binomial',
             weights=anes20.area.rural$V200010b)
summary(mod4c)

mod4d <- glm(trump.general20~therm.asian.americans20+
               therm.whites20+therm.hispanics20+
               racial.resentment20+
               black20+asian20+native20+hispanic20+other20+
               partyid20+econ.better20+
               age20+female20+education20+income20+protestant20,
             data=anes20.area.city,family='binomial',
             weights=anes20.area.city$V200010b)
summary(mod4d)



#Figure 4 and Appendix Table D: 
#2016 anti-asian attitudes on 2020 vote choice model
mod5a <- glm(trump.general20~therm.asian.americans16+
               therm.whites16+therm.hispanics16+
               racial.resentment16+
               black16+asian16+native16+hispanic16+other16+
               partyid16+econ.better16+
               age16+female16+education16+income16+protestant16,
             data=paneled, family='binomial', weights=paneled$V200011b)
summary(mod5a)

setup <- with(paneled,
              data.frame(therm.asian.americans16=c(0, 0.25, 0.5, 0.75, 1),
                         therm.whites16=mean(therm.whites16, na.rm=TRUE),
                         therm.hispanics16=mean(therm.hispanics16, na.rm=TRUE),
                         racial.resentment16=mean(racial.resentment16, na.rm=TRUE),
                         black16=mean(black16, na.rm=TRUE),
                         asian16=mean(asian16, na.rm=TRUE),
                         native16=mean(native16, na.rm=TRUE),
                         hispanic16=mean(hispanic16, na.rm=TRUE),
                         other16=mean(other16, na.rm=TRUE),
                         partyid16=mean(partyid16,na.rm=TRUE),
                         econ.better16=mean(econ.better16, na.rm=TRUE),
                         age16=mean(age16,na.rm=TRUE),
                         female16=mean(female16, na.rm=TRUE),
                         education16=mean(education16, na.rm=TRUE),
                         income16=mean(income16, na.rm=TRUE),
                         protestant16=mean(protestant16, na.rm=TRUE)))

setup

preds <- predict(mod5a, setup, type="response",
                 se.fit=TRUE)

preds

predf <- preds$fit

predf

lower <- preds$fit-(1.96*preds$se.fit)

lower

upper <- preds$fit+(1.96*preds$se.fit)

upper


#Figure 5; Appendix Table D

#anti-asian attitudes (2016) on vote switch (OLS model)
mod6a <- lm(change.trump20202016~therm.asian.americans16+
              therm.whites16+therm.hispanics16+
              racial.resentment16+
              black16+asian16+native16+hispanic16+other16+
              partyid16+econ.better16+
              age16+female16+education16+income16+protestant16,
            data=paneled, weights=paneled$V200011b)
summary(mod6a)

setup <- with(paneled,
              data.frame(therm.asian.americans16=c(0, 0.25, 0.5, 0.75, 1),
                         therm.whites16=mean(therm.whites16, na.rm=TRUE),
                         therm.hispanics16=mean(therm.hispanics16, na.rm=TRUE),
                         racial.resentment16=mean(racial.resentment16, na.rm=TRUE),
                         black16=mean(black16, na.rm=TRUE),
                         asian16=mean(asian16, na.rm=TRUE),
                         native16=mean(native16, na.rm=TRUE),
                         hispanic16=mean(hispanic16, na.rm=TRUE),
                         other16=mean(other16, na.rm=TRUE),
                         partyid16=mean(partyid16,na.rm=TRUE),
                         econ.better16=mean(econ.better16, na.rm=TRUE),
                         age16=mean(age16,na.rm=TRUE),
                         female16=mean(female16, na.rm=TRUE),
                         education16=mean(education16, na.rm=TRUE),
                         income16=mean(income16, na.rm=TRUE),
                         protestant16=mean(protestant16, na.rm=TRUE)))

setup

preds <- predict(mod6a, setup, type="response",
                 se.fit=TRUE)

preds

predf <- preds$fit

predf

lower <- preds$fit-(1.96*preds$se.fit)

lower

upper <- preds$fit+(1.96*preds$se.fit)

upper